@@ -153,6 +153,11 @@ export abstract class Reactor extends Component {
153
153
*/
154
154
private readonly _keyChain = new Map < Component , symbol > ( ) ;
155
155
156
+ // This is the keychain for creation, i.e. if Reactor R's mutation created reactor B,
157
+ // then R is B's creator, even if they are siblings. R should have access to B,
158
+ // at least semantically......?
159
+ private readonly _creatorKeyChain = new Map < Component , symbol > ( ) ;
160
+
156
161
/**
157
162
* This graph has in it all the dependencies implied by this container's
158
163
* ports, reactions, and connections.
@@ -375,7 +380,7 @@ export abstract class Reactor extends Component {
375
380
* @param key The key that verifies the containment relation between this
376
381
* reactor and the component, with at most one level of indirection.
377
382
*/
378
- public _getKey ( component : Trigger , key ?: symbol ) : symbol | undefined {
383
+ public _getKey ( component : Trigger , key ?: symbol , allowCreatorKey ?: boolean ) : symbol | undefined {
379
384
if ( component . _isContainedBy ( this ) || this . _key === key ) {
380
385
return this . _keyChain . get ( component ) ;
381
386
} else if (
@@ -386,6 +391,12 @@ export abstract class Reactor extends Component {
386
391
if ( owner !== null ) {
387
392
return owner . _getKey ( component , this . _keyChain . get ( owner ) ) ;
388
393
}
394
+ } else if ( allowCreatorKey ?? false ) {
395
+ console . log ( "trying to get key......" )
396
+ if ( this . _creatorKeyChain . get ( component ) != null ) {
397
+ return this . _creatorKeyChain . get ( component ) ;
398
+ }
399
+ return this . _creatorKeyChain . get ( component . getContainer ( ) ) ;
389
400
}
390
401
}
391
402
@@ -436,7 +447,7 @@ export abstract class Reactor extends Component {
436
447
this . reactor . _connectCall ( src , dst ) ;
437
448
} else if ( src instanceof IOPort && dst instanceof IOPort ) {
438
449
if ( this . reactor . canConnect ( src , dst ) === 2 ) {
439
- this . reactor . _elevatedConnect ( src , dst ) ;
450
+ throw new Error ( "Connection will fail due to " ) ;
440
451
} else {
441
452
this . reactor . _connect ( src , dst ) ;
442
453
}
@@ -1117,12 +1128,6 @@ export abstract class Reactor extends Component {
1117
1128
throw Error ( "Destination port is already occupied." ) ;
1118
1129
}
1119
1130
1120
- if ( ! ( src . checkKey ( this . _key ) && dst . checkKey ( this . _key ) ) ) {
1121
- // FIXME: dirty hack here
1122
- // Scoping issue. Does not possess valid key for src/dst.
1123
- return 2 ;
1124
- }
1125
-
1126
1131
if ( ! this . _runtime . isRunning ( ) ) {
1127
1132
// console.log("Connecting before running")
1128
1133
// Validate connections between callers and callees.
@@ -1245,11 +1250,12 @@ export abstract class Reactor extends Component {
1245
1250
) : void {
1246
1251
Log . debug ( this , ( ) => `connecting ${ src } and ${ dst } ` ) ;
1247
1252
// Register receiver for value propagation.
1248
- const writer = dst . asWritable ( this . _getKey ( dst ) ) ;
1253
+ console . log ( this . _getKey ( dst , undefined , true ) ) ;
1254
+ const writer = dst . asWritable ( this . _getKey ( dst , undefined , true ) ) ;
1249
1255
// Add dependency implied by connection to local graph.
1250
1256
this . _dependencyGraph . addEdge ( src , dst ) ;
1251
1257
src
1252
- . getManager ( this . _getKey ( src ) )
1258
+ . getManager ( this . _getKey ( src , undefined , true ) )
1253
1259
. addReceiver ( writer as unknown as WritablePort < S > ) ;
1254
1260
const val = src . get ( ) ;
1255
1261
if ( this . _runtime . isRunning ( ) && val !== undefined ) {
@@ -1592,7 +1598,9 @@ export abstract class Reactor extends Component {
1592
1598
if ( this . _getContainer ( ) === this ) {
1593
1599
throw new Error ( `Reactor ${ this } is self-contained. Adding sibling creates logical issue.` ) ;
1594
1600
}
1595
- return this . _getContainer ( ) . _uncheckedAddChild ( constructor , ...args ) ;
1601
+ const newReactor = this . _getContainer ( ) . _uncheckedAddChild ( constructor , ...args ) ;
1602
+ this . _creatorKeyChain . set ( newReactor , newReactor . _key ) ;
1603
+ return newReactor ;
1596
1604
}
1597
1605
1598
1606
public _elevatedConnect ( ...args : Parameters < Reactor [ "_connect" ] > ) : ReturnType < Reactor [ "_connect" ] > {
0 commit comments