@@ -22,35 +22,33 @@ export const collapseStringsAfterLengthAtom = atom<JsonViewerState['collapseStri
22
22
export const defaultInspectDepthAtom = atom < JsonViewerState [ 'defaultInspectDepth' ] | undefined > ( undefined )
23
23
export const objectSortKeysAtom = atom < JsonViewerState [ 'objectSortKeys' ] | undefined > ( undefined )
24
24
export const quotesOnKeysAtom = atom < JsonViewerState [ 'quotesOnKeys' ] | undefined > ( undefined )
25
- export const inspectCacheAtom = atom < JsonViewerState [ 'inspectCache' ] > ( { } )
26
25
export const hoverPathAtom = atom < JsonViewerState [ 'hoverPath' ] | null > ( null )
27
26
export const registryAtom = atom < TypeRegistryState [ 'registry' ] > ( [ ] )
28
27
28
+ const _inspectCacheAtom = atom < JsonViewerState [ 'inspectCache' ] > ( { } )
29
29
// TODO check: if memory leaks, add to last line of useEffect:
30
30
// return () => { atomFamily.remove ... // Anything in here is fired on component unmount }
31
- export const getInspectCacheAtom = atomFamily ( ( { path, nestedIndex } ) => atom (
31
+ export const inspectCacheAtom = atomFamily ( ( { path, nestedIndex } ) => atom (
32
32
( get ) => {
33
33
const target = nestedIndex === undefined
34
34
? path . join ( '.' )
35
35
: `${ path . join ( '.' ) } [${ nestedIndex } ]nt`
36
- return get ( inspectCacheAtom ) [ target ]
37
- }
38
- ) , deepEqual )
39
- export const setInspectCacheAtom = atom (
40
- ( get ) => get ( inspectCacheAtom ) ,
36
+ return get ( _inspectCacheAtom ) [ target ]
37
+ } ,
41
38
( get , set , { path, action, nestedIndex } ) => {
42
39
const target = nestedIndex === undefined
43
40
? path . join ( '.' )
44
41
: `${ path . join ( '.' ) } [${ nestedIndex } ]nt`
45
- const inspectCache = get ( inspectCacheAtom )
46
- return set ( inspectCacheAtom , {
42
+ const inspectCache = get ( _inspectCacheAtom )
43
+ return set ( _inspectCacheAtom , {
47
44
...inspectCache ,
48
45
[ target ] : typeof action === 'function'
49
46
? action ( inspectCache [ target ] )
50
47
: action
51
48
} )
52
49
}
53
- )
50
+ ) , deepEqual )
51
+
54
52
export const setHoverAtom = atom (
55
53
( get ) => get ( hoverPathAtom ) ,
56
54
( _get , set , { path, nestedIndex } ) => {
0 commit comments