@@ -153,6 +153,11 @@ export abstract class Reactor extends Component {
153153 */
154154 private readonly _keyChain = new Map < Component , symbol > ( ) ;
155155
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+
156161 /**
157162 * This graph has in it all the dependencies implied by this container's
158163 * ports, reactions, and connections.
@@ -375,7 +380,7 @@ export abstract class Reactor extends Component {
375380 * @param key The key that verifies the containment relation between this
376381 * reactor and the component, with at most one level of indirection.
377382 */
378- public _getKey ( component : Trigger , key ?: symbol ) : symbol | undefined {
383+ public _getKey ( component : Trigger , key ?: symbol , allowCreatorKey ?: boolean ) : symbol | undefined {
379384 if ( component . _isContainedBy ( this ) || this . _key === key ) {
380385 return this . _keyChain . get ( component ) ;
381386 } else if (
@@ -386,6 +391,12 @@ export abstract class Reactor extends Component {
386391 if ( owner !== null ) {
387392 return owner . _getKey ( component , this . _keyChain . get ( owner ) ) ;
388393 }
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 ( ) ) ;
389400 }
390401 }
391402
@@ -436,7 +447,7 @@ export abstract class Reactor extends Component {
436447 this . reactor . _connectCall ( src , dst ) ;
437448 } else if ( src instanceof IOPort && dst instanceof IOPort ) {
438449 if ( this . reactor . canConnect ( src , dst ) === 2 ) {
439- this . reactor . _elevatedConnect ( src , dst ) ;
450+ throw new Error ( "Connection will fail due to " ) ;
440451 } else {
441452 this . reactor . _connect ( src , dst ) ;
442453 }
@@ -1117,12 +1128,6 @@ export abstract class Reactor extends Component {
11171128 throw Error ( "Destination port is already occupied." ) ;
11181129 }
11191130
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-
11261131 if ( ! this . _runtime . isRunning ( ) ) {
11271132 // console.log("Connecting before running")
11281133 // Validate connections between callers and callees.
@@ -1245,11 +1250,12 @@ export abstract class Reactor extends Component {
12451250 ) : void {
12461251 Log . debug ( this , ( ) => `connecting ${ src } and ${ dst } ` ) ;
12471252 // 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 ) ) ;
12491255 // Add dependency implied by connection to local graph.
12501256 this . _dependencyGraph . addEdge ( src , dst ) ;
12511257 src
1252- . getManager ( this . _getKey ( src ) )
1258+ . getManager ( this . _getKey ( src , undefined , true ) )
12531259 . addReceiver ( writer as unknown as WritablePort < S > ) ;
12541260 const val = src . get ( ) ;
12551261 if ( this . _runtime . isRunning ( ) && val !== undefined ) {
@@ -1592,7 +1598,9 @@ export abstract class Reactor extends Component {
15921598 if ( this . _getContainer ( ) === this ) {
15931599 throw new Error ( `Reactor ${ this } is self-contained. Adding sibling creates logical issue.` ) ;
15941600 }
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 ;
15961604 }
15971605
15981606 public _elevatedConnect ( ...args : Parameters < Reactor [ "_connect" ] > ) : ReturnType < Reactor [ "_connect" ] > {
0 commit comments