File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -323,10 +323,12 @@ export class Realm {
323323
324324 if ( resolved ) {
325325 const value = transientState . get ( id )
326- this . subscriptions . use ( id , ( nodeSubscriptions ) => {
327- for ( const subscription of nodeSubscriptions ) {
328- subscription ( value )
329- }
326+ this . inContext ( ( ) => {
327+ this . subscriptions . use ( id , ( nodeSubscriptions ) => {
328+ for ( const subscription of nodeSubscriptions ) {
329+ subscription ( value )
330+ }
331+ } )
330332 } )
331333 this . singletonSubscriptions . get ( id ) ?.( value )
332334 } else {
@@ -1112,15 +1114,23 @@ export class Realm {
11121114 ? this . cellInstance ( definition . initial , definition . distinct , node )
11131115 : this . signalInstance ( definition . distinct , node ) ,
11141116 ( node$ ) => {
1115- currentRealm$$ = this
1116- definition . init ( this , node$ )
1117- currentRealm$$ = undefined
1117+ this . inContext ( ( ) => {
1118+ definition . init ( this , node$ )
1119+ } )
11181120 }
11191121 )
11201122 }
11211123 return node
11221124 }
11231125
1126+ inContext < T > ( fn : ( ) => T ) : T {
1127+ const prevRealm = currentRealm$$
1128+ currentRealm$$ = this
1129+ const result = fn ( )
1130+ currentRealm$$ = prevRealm
1131+ return result
1132+ }
1133+
11241134 /**
11251135 * Convenient for mutation of cells that contian non-primitive values (e.g. arrays, or objects).
11261136 * Specifies that the cell value should be changed when source emits, with the result of the map callback parameter.
You can’t perform that action at this time.
0 commit comments