@@ -3,90 +3,90 @@ import { createContext } from 'solid-js'
33import { createStore } from 'solid-js/store'
44import { tryParseJson } from '../utils/sanitize'
55import {
6- TANSTACK_DEVTOOLS_SETTINGS ,
7- TANSTACK_DEVTOOLS_STATE ,
8- getStorageItem ,
9- setStorageItem ,
6+ TANSTACK_DEVTOOLS_SETTINGS ,
7+ TANSTACK_DEVTOOLS_STATE ,
8+ getStorageItem ,
9+ setStorageItem ,
1010} from '../utils/storage'
1111import { type DevtoolsStore , initialState } from './devtools-store'
1212import type { JSX } from 'solid-js/jsx-runtime'
1313
1414export interface DevtoolsPlugin {
15- name : string | ( ( el : HTMLDivElement ) => void )
16- id : string
17- component : ( el : HTMLDivElement ) => void
15+ name : string | ( ( el : HTMLDivElement ) => void )
16+ id : string
17+ component : ( el : HTMLDivElement ) => void
1818}
1919
2020export const DevtoolsContext = createContext < {
21- store : DevtoolsStore
22- setStore : Setter < DevtoolsStore >
21+ store : DevtoolsStore
22+ setStore : Setter < DevtoolsStore >
2323} > ( )
2424
2525interface ContextProps {
26- children : JSX . Element
27- plugins ?: DevtoolsPlugin [ ]
28- config ?: DevtoolsSettings
26+ children : JSX . Element
27+ plugins ?: DevtoolsPlugin [ ]
28+ config ?: DevtoolsSettings
2929}
3030
3131export const getSettings = ( ) => {
32- const settingsString = getStorageItem ( TANSTACK_DEVTOOLS_SETTINGS )
33- const settings = tryParseJson < DevtoolsStore [ 'settings' ] > ( settingsString )
34- return {
35- ...settings ,
36- }
32+ const settingsString = getStorageItem ( TANSTACK_DEVTOOLS_SETTINGS )
33+ const settings = tryParseJson < DevtoolsStore [ 'settings' ] > ( settingsString )
34+ return {
35+ ...settings ,
36+ }
3737}
3838
3939export const getExistingStateFromStorage = (
40- config ?: DevtoolsSettings ,
41- plugins ?: DevtoolsPlugin [ ] ,
40+ config ?: DevtoolsSettings ,
41+ plugins ?: DevtoolsPlugin [ ] ,
4242) => {
43- const existingState = getStorageItem ( TANSTACK_DEVTOOLS_STATE )
44- const settings = getSettings ( )
43+ const existingState = getStorageItem ( TANSTACK_DEVTOOLS_STATE )
44+ const settings = getSettings ( )
4545
46- const state : DevtoolsStore = {
47- ...initialState ,
48- plugins : plugins || [ ] ,
49- state : {
50- ...initialState . state ,
51- ...( existingState ? JSON . parse ( existingState ) : { } ) ,
52- } ,
53- settings : {
54- ...initialState . settings ,
55- ...config ,
56- ...settings ,
57- } ,
58- }
59- return state
46+ const state : DevtoolsStore = {
47+ ...initialState ,
48+ plugins : plugins || [ ] ,
49+ state : {
50+ ...initialState . state ,
51+ ...( existingState ? JSON . parse ( existingState ) : { } ) ,
52+ } ,
53+ settings : {
54+ ...initialState . settings ,
55+ ...config ,
56+ ...settings ,
57+ } ,
58+ }
59+ return state
6060}
6161
6262export type DevtoolsSettings = DevtoolsStore [ 'settings' ]
6363
6464export const DevtoolsProvider = ( props : ContextProps ) => {
65- const [ store , setStore ] = createStore (
66- getExistingStateFromStorage ( props . config , props . plugins ) ,
67- )
65+ const [ store , setStore ] = createStore (
66+ getExistingStateFromStorage ( props . config , props . plugins ) ,
67+ )
6868
69- const value = {
70- store,
71- setStore : (
72- updater : ( prev : DevtoolsStore ) => DevtoolsStore | Partial < DevtoolsStore > ,
73- ) => {
74- const newState = updater ( store )
75- const { settings, state : internalState } = newState
76- // Store user settings for dev tools into local storage
77- setStorageItem ( TANSTACK_DEVTOOLS_SETTINGS , JSON . stringify ( settings ) )
78- // Store general state into local storage
79- setStorageItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( internalState ) )
80- setStore ( ( prev ) => ( {
81- ...prev ,
82- ...newState ,
83- } ) )
84- } ,
85- }
69+ const value = {
70+ store,
71+ setStore : (
72+ updater : ( prev : DevtoolsStore ) => DevtoolsStore | Partial < DevtoolsStore > ,
73+ ) => {
74+ const newState = updater ( store )
75+ const { settings, state : internalState } = newState
76+ // Store user settings for dev tools into local storage
77+ setStorageItem ( TANSTACK_DEVTOOLS_SETTINGS , JSON . stringify ( settings ) )
78+ // Store general state into local storage
79+ setStorageItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( internalState ) )
80+ setStore ( ( prev ) => ( {
81+ ...prev ,
82+ ...newState ,
83+ } ) )
84+ } ,
85+ }
8686
87- return (
88- < DevtoolsContext . Provider value = { value } >
89- { props . children }
90- </ DevtoolsContext . Provider >
91- )
87+ return (
88+ < DevtoolsContext . Provider value = { value } >
89+ { props . children }
90+ </ DevtoolsContext . Provider >
91+ )
9292}
0 commit comments