tx-component.ts is TypeScript decorator helping you defining a component with a mountpoint. the TxComponent decorator implicit add a mountpoint as property and register is under the 'selector' property of the decorator. Also tasks and undos methods are as specifying in the decorator configuration.
NOTE: due to some hard time the TypeScript decorator is giving me the 'tasks' and 'undos' methods names can't be changes. later on you will be able to define any methods to like.
Use it as follow:
import createLogger from 'logging';
const logger = createLogger('Job-Test');
import { TxComponent } from '../../src/tx-component';
import { TxTask } from '../../src/tx-task';
@TxComponent({
selector: 'GITHUB::GIST::D1',
tasks: 'tasks',
undos: 'undos'
})
export class D1Component {
constructor() {
logger.info("[D1Component:constructor] ctor ..");
}
tasks(data) {
logger.info('[D1Component:tasks] is called, data = ' + JSON.stringify(data));
this.mountpoint().reply().next(new TxTask('[D1Component:tasks] tasks from D1', 'ok', data['data']));
}
undos(data) {
logger.info('[D1Component:undos] is called, data = ' + JSON.stringify(data));
this.mountpoint().reply().next(new TxTask('[D1Component:tasks] undos from D1', 'ok', data['data']));
}
}
Creating a component using Angular component style. Decorator config:
selector: the component's mountpoint identifier in the registry.
tasks: a method run when some tasks message is received from mountpoint.
undos: a method run when some undos message is received from mountpoint.
For example if the chain including C1, C2, C3. After the execution, calling to undo with backward order will initiate a sequence of undo call to each component in reverse order, C3, C2, C1.
usage
let job = new TxJob(); // or create througth the TxJobRegistry
job.add(TxMountPointRegistry.instance.get('GITHUB::GIST::C1'));
job.add(TxMountPointRegistry.instance.get('GITHUB::GIST::C2'));
job.add(TxMountPointRegistry.instance.get('GITHUB::GIST::C3'));
job.execute(new TxTask(
'create',
'',
{something: 'more data here'})
);
job.undo(backword);