@@ -8,7 +8,7 @@ type OnUnmount = () => void
88type Getter = Parameters < AnyAtom [ 'read' ] > [ 0 ]
99type Setter = Parameters < AnyWritableAtom [ 'write' ] > [ 1 ]
1010
11- const isSelfAtom = ( atom : AnyAtom , a : AnyAtom ) =>
11+ const isSelfAtom = ( atom : AnyAtom , a : AnyAtom ) : boolean =>
1212 atom . unstable_is ? atom . unstable_is ( a ) : a === atom
1313
1414const hasInitialValue = < T extends Atom < AnyValue > > (
@@ -20,7 +20,7 @@ const isActuallyWritableAtom = (atom: AnyAtom): atom is AnyWritableAtom =>
2020 ! ! ( atom as AnyWritableAtom ) . write
2121
2222type CancelPromise = ( next ?: Promise < unknown > ) => void
23- const cancelPromiseMap = new WeakMap < Promise < unknown > , CancelPromise > ( )
23+ const cancelPromiseMap : WeakMap < Promise < unknown > , CancelPromise > = new WeakMap ( )
2424
2525const registerCancelPromise = (
2626 promise : Promise < unknown > ,
@@ -124,6 +124,8 @@ type Mounted = {
124124 u ?: OnUnmount
125125}
126126
127+ type MountedAtoms = Set < AnyAtom >
128+
127129// for debugging purpose only
128130type StoreListenerRev2 = (
129131 action :
@@ -134,7 +136,19 @@ type StoreListenerRev2 = (
134136 | { type : 'restore' ; flushed : Set < AnyAtom > } ,
135137) => void
136138
137- type MountedAtoms = Set < AnyAtom >
139+ type Store = {
140+ get : < Value > ( atom : Atom < Value > ) => Value
141+ set : < Value , Args extends unknown [ ] , Result > (
142+ atom : WritableAtom < Value , Args , Result > ,
143+ ...args : Args
144+ ) => Result
145+ sub : ( atom : AnyAtom , listener : ( ) => void ) => ( ) => void
146+ dev_subscribe_store ?: ( l : StoreListenerRev2 , rev : 2 ) => ( ) => void
147+ dev_get_mounted_atoms ?: ( ) => IterableIterator < AnyAtom >
148+ dev_get_atom_state ?: ( a : AnyAtom ) => AtomState | undefined
149+ dev_get_mounted ?: ( a : AnyAtom ) => Mounted | undefined
150+ dev_restore_atoms ?: ( values : Iterable < readonly [ AnyAtom , AnyValue ] > ) => void
151+ }
138152
139153/**
140154 * Create a new store. Each store is an independent, isolated universe of atom
@@ -152,7 +166,7 @@ type MountedAtoms = Set<AnyAtom>
152166 *
153167 * @returns A store.
154168 */
155- export const createStore = ( ) => {
169+ export const createStore = ( ) : Store => {
156170 const atomStateMap = new WeakMap < AnyAtom , AtomState > ( )
157171 const mountedMap = new WeakMap < AnyAtom , Mounted > ( )
158172 const pendingStack : Set < AnyAtom > [ ] = [ ]
@@ -824,11 +838,9 @@ export const createStore = () => {
824838 }
825839}
826840
827- type Store = ReturnType < typeof createStore >
828-
829841let defaultStore : Store | undefined
830842
831- export const getDefaultStore = ( ) => {
843+ export const getDefaultStore = ( ) : Store => {
832844 if ( ! defaultStore ) {
833845 defaultStore = createStore ( )
834846 if ( import . meta. env ?. MODE !== 'production' ) {
0 commit comments