@@ -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.
@@ -387,6 +392,9 @@ export abstract class Reactor extends Component {
387392 return owner . _getKey ( component , this . _keyChain . get ( owner ) ) ;
388393 }
389394 }
395+ return component
396+ . getContainer ( )
397+ . _getKey ( component , this . _creatorKeyChain . get ( component . getContainer ( ) ) ) ;
390398 }
391399
392400 /**
@@ -1555,6 +1563,36 @@ export abstract class Reactor extends Component {
15551563 toString ( ) : string {
15561564 return this . _getFullyQualifiedName ( ) ;
15571565 }
1566+
1567+ protected _addChild < R extends Reactor , G extends unknown [ ] > (
1568+ constructor : new ( container : Reactor , ...args : G ) => R ,
1569+ ...args : G
1570+ ) : R {
1571+ const newReactor = new constructor ( this , ...args ) ;
1572+ return newReactor ;
1573+ }
1574+
1575+ protected _addSibling < R extends Reactor , G extends unknown [ ] > (
1576+ constructor : new ( container : Reactor , ...args : G ) => R ,
1577+ ...args : G
1578+ ) : R {
1579+ if ( this . _getContainer ( ) == null ) {
1580+ throw new Error (
1581+ `Reactor ${ this } does not have a parent. Sibling is not well-defined.`
1582+ ) ;
1583+ }
1584+ if ( this . _getContainer ( ) === this ) {
1585+ throw new Error (
1586+ `Reactor ${ this } is self-contained. Adding sibling creates logical issue.`
1587+ ) ;
1588+ }
1589+ const newReactor = this . _getContainer ( ) . _addChild (
1590+ constructor ,
1591+ ...args
1592+ ) ;
1593+ this . _creatorKeyChain . set ( newReactor , newReactor . _key ) ;
1594+ return newReactor ;
1595+ }
15581596}
15591597
15601598/*
0 commit comments