File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,19 +18,23 @@ export function useAtomsSnapshot(scope?: Scope): AtomsSnapshot {
1818
1919 const [ store , devStore ] = scopeContainer
2020
21- const [ atoms , setAtoms ] = useState ( devStore . atoms )
21+ const [ atomsSnaphost , setAtomsSnaphost ] = useState < AtomsSnapshot > ( new Map ( ) )
2222 useEffect ( ( ) => {
23- const callback = ( ) => setAtoms ( devStore . atoms )
23+ const callback = ( ) => {
24+ const { atoms } = devStore
25+ const atomToAtomValueTuples = atoms
26+ . filter ( ( atom ) => ! ! store [ DEV_GET_MOUNTED ] ?.( atom ) )
27+ . map < [ Atom < unknown > , unknown ] > ( ( atom ) => {
28+ const atomState =
29+ store [ DEV_GET_ATOM_STATE ] ?.( atom ) ?? ( { } as AtomState )
30+ return [ atom , atomState . v ]
31+ } )
32+ setAtomsSnaphost ( new Map ( atomToAtomValueTuples ) )
33+ }
2434 const unsubscribe = devStore . subscribe ( callback )
2535 callback ( )
2636 return unsubscribe
27- } , [ devStore ] )
37+ } , [ store , devStore ] )
2838
29- const atomToAtomValueTuples = atoms
30- . filter ( ( atom ) => ! ! store [ DEV_GET_MOUNTED ] ?.( atom ) )
31- . map < [ Atom < unknown > , unknown ] > ( ( atom ) => {
32- const atomState = store [ DEV_GET_ATOM_STATE ] ?.( atom ) ?? ( { } as AtomState )
33- return [ atom , atomState . v ]
34- } )
35- return new Map ( atomToAtomValueTuples )
39+ return atomsSnaphost
3640}
You can’t perform that action at this time.
0 commit comments