@@ -2,92 +2,92 @@ import { createContext } from 'solid-js'
22import { createStore } from 'solid-js/store'
33import { tryParseJson } from '../utils/sanitize'
44import {
5- TANSTACK_DEVTOOLS_SETTINGS ,
6- TANSTACK_DEVTOOLS_STATE ,
7- getStorageItem ,
8- setStorageItem ,
5+ TANSTACK_DEVTOOLS_SETTINGS ,
6+ TANSTACK_DEVTOOLS_STATE ,
7+ getStorageItem ,
8+ setStorageItem ,
99} from '../utils/storage'
1010import { initialState } from './devtools-store'
11- import type { DevtoolsStore } from './devtools-store' ;
11+ import type { DevtoolsStore } from './devtools-store'
1212import type { Setter } from 'solid-js'
1313import type { JSX } from 'solid-js/jsx-runtime'
1414
1515export interface DevtoolsPlugin {
16- name : string | ( ( el : HTMLDivElement ) => void )
17- id : string
18- component : ( el : HTMLDivElement ) => void
16+ name : string | ( ( el : HTMLDivElement ) => void )
17+ id : string
18+ component : ( el : HTMLDivElement ) => void
1919}
2020
2121export const DevtoolsContext = createContext < {
22- store : DevtoolsStore
23- setStore : Setter < DevtoolsStore >
22+ store : DevtoolsStore
23+ setStore : Setter < DevtoolsStore >
2424} > ( )
2525
2626interface ContextProps {
27- children : JSX . Element
28- plugins ?: Array < DevtoolsPlugin >
29- config ?: DevtoolsSettings
27+ children : JSX . Element
28+ plugins ?: Array < DevtoolsPlugin >
29+ config ?: DevtoolsSettings
3030}
3131
3232const getSettings = ( ) => {
33- const settingsString = getStorageItem ( TANSTACK_DEVTOOLS_SETTINGS )
34- const settings = tryParseJson < DevtoolsStore [ 'settings' ] > ( settingsString )
35- return {
36- ...settings ,
37- }
33+ const settingsString = getStorageItem ( TANSTACK_DEVTOOLS_SETTINGS )
34+ const settings = tryParseJson < DevtoolsStore [ 'settings' ] > ( settingsString )
35+ return {
36+ ...settings ,
37+ }
3838}
3939
4040const getExistingStateFromStorage = (
41- config ?: DevtoolsSettings ,
42- plugins ?: Array < DevtoolsPlugin > ,
41+ config ?: DevtoolsSettings ,
42+ plugins ?: Array < DevtoolsPlugin > ,
4343) => {
44- const existingState = getStorageItem ( TANSTACK_DEVTOOLS_STATE )
45- const settings = getSettings ( )
44+ const existingState = getStorageItem ( TANSTACK_DEVTOOLS_STATE )
45+ const settings = getSettings ( )
4646
47- const state : DevtoolsStore = {
48- ...initialState ,
49- plugins : plugins || [ ] ,
50- state : {
51- ...initialState . state ,
52- ...( existingState ? JSON . parse ( existingState ) : { } ) ,
53- } ,
54- settings : {
55- ...initialState . settings ,
56- ...config ,
57- ...settings ,
58- } ,
59- }
60- return state
47+ const state : DevtoolsStore = {
48+ ...initialState ,
49+ plugins : plugins || [ ] ,
50+ state : {
51+ ...initialState . state ,
52+ ...( existingState ? JSON . parse ( existingState ) : { } ) ,
53+ } ,
54+ settings : {
55+ ...initialState . settings ,
56+ ...config ,
57+ ...settings ,
58+ } ,
59+ }
60+ return state
6161}
6262
6363export type DevtoolsSettings = DevtoolsStore [ 'settings' ]
6464
6565export const DevtoolsProvider = ( props : ContextProps ) => {
66- const [ store , setStore ] = createStore (
67- getExistingStateFromStorage ( props . config , props . plugins ) ,
68- )
66+ const [ store , setStore ] = createStore (
67+ getExistingStateFromStorage ( props . config , props . plugins ) ,
68+ )
6969
70- const value = {
71- store,
72- setStore : (
73- updater : ( prev : DevtoolsStore ) => DevtoolsStore | Partial < DevtoolsStore > ,
74- ) => {
75- const newState = updater ( store )
76- const { settings, state : internalState } = newState
77- // Store user settings for dev tools into local storage
78- setStorageItem ( TANSTACK_DEVTOOLS_SETTINGS , JSON . stringify ( settings ) )
79- // Store general state into local storage
80- setStorageItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( internalState ) )
81- setStore ( ( prev ) => ( {
82- ...prev ,
83- ...newState ,
84- } ) )
85- } ,
86- }
70+ const value = {
71+ store,
72+ setStore : (
73+ updater : ( prev : DevtoolsStore ) => DevtoolsStore | Partial < DevtoolsStore > ,
74+ ) => {
75+ const newState = updater ( store )
76+ const { settings, state : internalState } = newState
77+ // Store user settings for dev tools into local storage
78+ setStorageItem ( TANSTACK_DEVTOOLS_SETTINGS , JSON . stringify ( settings ) )
79+ // Store general state into local storage
80+ setStorageItem ( TANSTACK_DEVTOOLS_STATE , JSON . stringify ( internalState ) )
81+ setStore ( ( prev ) => ( {
82+ ...prev ,
83+ ...newState ,
84+ } ) )
85+ } ,
86+ }
8787
88- return (
89- < DevtoolsContext . Provider value = { value } >
90- { props . children }
91- </ DevtoolsContext . Provider >
92- )
88+ return (
89+ < DevtoolsContext . Provider value = { value } >
90+ { props . children }
91+ </ DevtoolsContext . Provider >
92+ )
9393}
0 commit comments