TxMountPoint

  • a class enable two ways communication between any two components.

  • it include two RxJS subjects one for tasks and other for reply.

Defining a mount point is as:

// get a new mount-point under the name 'GITHUB::GIST::C2' and save on the registry
mountpoint = TxMountPointRegistry.instance.create('GITHUB::GIST::C2');    

Mountpoint objects are kept in TxMountPointRegistry by their identifier (a selector) which could be a string or a Symbol.

The example above it using a string as identifier but this one is working as well:

// get a new mount-point under the name 'GITHUB::GIST::C2' and save on the registry
mountpoint = TxMountPointRegistry.instance.create(Symbol('GITHUB::GIST::C2');

NOTE: when you use Symbol make sure they all define in one central place otherwise you will not able to restore a mountpoint since the Symbol will change. For example:

class Names {
  static GITHUB_GIST_C1 = Symbol('GITHUB_GIST_C1');
  static GITHUB_GIST_C2 = Symbol('GITHUB_GIST_C2');
}
mountpoint = TxMountPointRegistry.instance.create(Names.GITHUB_GIST_C1);
  • Component

    • is any regular class which has a mount-point.

    • it register it's own mount point on TxMountPointRegistry under some name.

    • subscribe on tasks subject of the mount-point ready to get task messages.

    • reply back on the reply subject on the mount-point.

    For example

    class C1Component {
        mountpoint = TxMountPointRegistry.instance.create('GITHUB::GIST::C1');    
        task: any;
     
        constructor() {
          this.mountpoint.tasks().subscribe(
            (task) => {
              logger.info('[C1Component:task] got task = ' + JSON.stringify(task, undefined, 2));
              this.task = task;
              
              // C1 got a task send reply to who ever was that                  
              mountpoint.reply().next(new TxTask('get', '', task['data']));
            }
          )  
        }
     
       .
       .

Last updated