@@ -89,17 +89,24 @@ type ChangedAtoms = SetLike<AnyAtom>
8989type Callbacks = SetLike < ( ) => void >
9090
9191type AtomRead = < Value > (
92+ buildingBlocks : Readonly < BuildingBlocks > ,
9293 store : Store ,
9394 atom : Atom < Value > ,
9495 ...params : Parameters < Atom < Value > [ 'read' ] >
9596) => Value
9697type AtomWrite = < Value , Args extends unknown [ ] , Result > (
98+ buildingBlocks : Readonly < BuildingBlocks > ,
9799 store : Store ,
98100 atom : WritableAtom < Value , Args , Result > ,
99101 ...params : Parameters < WritableAtom < Value , Args , Result > [ 'write' ] >
100102) => Result
101- type AtomOnInit = < Value > ( store : Store , atom : Atom < Value > ) => void
103+ type AtomOnInit = < Value > (
104+ buildingBlocks : Readonly < BuildingBlocks > ,
105+ store : Store ,
106+ atom : Atom < Value > ,
107+ ) => void
102108type AtomOnMount = < Value , Args extends unknown [ ] , Result > (
109+ buildingBlocks : Readonly < BuildingBlocks > ,
103110 store : Store ,
104111 atom : WritableAtomWithOnMount < Value , Args , Result > ,
105112 setAtom : ( ...args : Args ) => Result ,
@@ -179,11 +186,13 @@ type EnhanceBuildingBlocks = (
179186type AbortHandlersMap = WeakMapLike < PromiseLike < unknown > , Set < ( ) => void > >
180187type RegisterAbortHandler = < T > (
181188 buildingBlocks : Readonly < BuildingBlocks > ,
189+ store : Store ,
182190 promise : PromiseLike < T > ,
183191 abortHandler : ( ) => void ,
184192) => void
185193type AbortPromise = < T > (
186194 buildingBlocks : Readonly < BuildingBlocks > ,
195+ store : Store ,
187196 promise : PromiseLike < T > ,
188197) => void
189198type StoreEpochHolder = [ n : EpochNumber ]
@@ -417,14 +426,26 @@ function initializeStoreHooks(storeHooks: StoreHooks): Required<StoreHooks> {
417426// Main functions
418427//
419428
420- const BUILDING_BLOCK_atomRead : AtomRead = ( _store , atom , ...params ) =>
421- atom . read ( ...params )
422- const BUILDING_BLOCK_atomWrite : AtomWrite = ( _store , atom , ...params ) =>
423- atom . write ( ...params )
424- const BUILDING_BLOCK_atomOnInit : AtomOnInit = ( store , atom ) =>
429+ const BUILDING_BLOCK_atomRead : AtomRead = (
430+ _buildingBlocks ,
431+ _store ,
432+ atom ,
433+ ...params
434+ ) => atom . read ( ...params )
435+ const BUILDING_BLOCK_atomWrite : AtomWrite = (
436+ _buildingBlocks ,
437+ _store ,
438+ atom ,
439+ ...params
440+ ) => atom . write ( ...params )
441+ const BUILDING_BLOCK_atomOnInit : AtomOnInit = ( _buildingBlocks , store , atom ) =>
425442 atom . INTERNAL_onInit ?.( store )
426- const BUILDING_BLOCK_atomOnMount : AtomOnMount = ( _store , atom , setAtom ) =>
427- atom . onMount ?.( setAtom )
443+ const BUILDING_BLOCK_atomOnMount : AtomOnMount = (
444+ _buildingBlocks ,
445+ _store ,
446+ atom ,
447+ setAtom ,
448+ ) => atom . onMount ?.( setAtom )
428449
429450const BUILDING_BLOCK_ensureAtomState : EnsureAtomState = (
430451 buildingBlocks ,
@@ -442,7 +463,7 @@ const BUILDING_BLOCK_ensureAtomState: EnsureAtomState = (
442463 atomState = { d : new Map ( ) , p : new Set ( ) , n : 0 }
443464 atomStateMap . set ( atom , atomState )
444465 storeHooks . i ?.( atom )
445- atomOnInit ?.( store , atom )
466+ atomOnInit ?.( buildingBlocks , store , atom )
446467 }
447468 return atomState as never
448469}
@@ -744,15 +765,21 @@ const BUILDING_BLOCK_readAtomState: ReadAtomState = (
744765 if ( import . meta. env ?. MODE !== 'production' ) {
745766 storeMutationSet . delete ( store )
746767 }
747- const valueOrPromise = atomRead ( store , atom , getter , options as never )
768+ const valueOrPromise = atomRead (
769+ buildingBlocks ,
770+ store ,
771+ atom ,
772+ getter ,
773+ options as never ,
774+ )
748775 if ( import . meta. env ?. MODE !== 'production' && storeMutationSet . has ( store ) ) {
749776 console . warn (
750777 'Detected store mutation during atom read. This is not supported.' ,
751778 )
752779 }
753780 setAtomStateValueOrPromise ( buildingBlocks , store , atom , valueOrPromise )
754781 if ( isPromiseLike ( valueOrPromise ) ) {
755- registerAbortHandler ( buildingBlocks , valueOrPromise , ( ) =>
782+ registerAbortHandler ( buildingBlocks , store , valueOrPromise , ( ) =>
756783 controller ?. abort ( ) ,
757784 )
758785 const settle = ( ) => {
@@ -861,7 +888,7 @@ const BUILDING_BLOCK_writeAtomState: WriteAtomState = (
861888 }
862889 }
863890 try {
864- return atomWrite ( store , atom , getter , setter , ...args )
891+ return atomWrite ( buildingBlocks , store , atom , getter , setter , ...args )
865892 } finally {
866893 isSync = false
867894 }
@@ -947,7 +974,7 @@ const BUILDING_BLOCK_mountAtom: MountAtom = (buildingBlocks, store, atom) => {
947974 }
948975 }
949976 try {
950- const onUnmount = atomOnMount ( store , atom , setAtom )
977+ const onUnmount = atomOnMount ( buildingBlocks , store , atom , setAtom )
951978 if ( onUnmount ) {
952979 mounted ! . u = ( ) => {
953980 isSync = true
@@ -1034,7 +1061,7 @@ const BUILDING_BLOCK_setAtomStateValueOrPromise: SetAtomStateValueOrPromise = (
10341061 if ( ! hasPrevValue || ! Object . is ( prevValue , atomState . v ) ) {
10351062 ++ atomState . n
10361063 if ( isPromiseLike ( prevValue ) ) {
1037- abortPromise ( buildingBlocks , prevValue )
1064+ abortPromise ( buildingBlocks , store , prevValue )
10381065 }
10391066 }
10401067}
@@ -1087,6 +1114,7 @@ const BUILDING_BLOCK_storeSub: StoreSub = (
10871114
10881115const BUILDING_BLOCK_registerAbortHandler : RegisterAbortHandler = (
10891116 buildingBlocks ,
1117+ _store ,
10901118 promise ,
10911119 abortHandler ,
10921120) => {
@@ -1101,7 +1129,11 @@ const BUILDING_BLOCK_registerAbortHandler: RegisterAbortHandler = (
11011129 abortHandlers . add ( abortHandler )
11021130}
11031131
1104- const BUILDING_BLOCK_abortPromise : AbortPromise = ( buildingBlocks , promise ) => {
1132+ const BUILDING_BLOCK_abortPromise : AbortPromise = (
1133+ buildingBlocks ,
1134+ _store ,
1135+ promise ,
1136+ ) => {
11051137 const abortHandlersMap = buildingBlocks [ 25 ]
11061138 const abortHandlers = abortHandlersMap . get ( promise )
11071139 abortHandlers ?. forEach ( ( fn ) => fn ( ) )
0 commit comments