lot of changes for first actual use
This commit is contained in:
43
dist/callchain.js
vendored
43
dist/callchain.js
vendored
@ -2,14 +2,22 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const log = require("./log");
|
||||
const events = require("events");
|
||||
class LastChainItem {
|
||||
begin() {
|
||||
}
|
||||
send(message) {
|
||||
log.info(`Last chain item, final result ${message}`);
|
||||
}
|
||||
}
|
||||
let lastChainItem = new LastChainItem();
|
||||
class AChainItem extends events.EventEmitter {
|
||||
constructor(label) {
|
||||
super();
|
||||
this._label = label;
|
||||
this._next = null;
|
||||
this._next = lastChainItem;
|
||||
}
|
||||
toString() {
|
||||
return `<${this._label}`;
|
||||
return `<${this._label}>`;
|
||||
}
|
||||
registerNext(next) {
|
||||
this._next = next;
|
||||
@ -19,32 +27,33 @@ class AChainItem extends events.EventEmitter {
|
||||
}
|
||||
}
|
||||
exports.AChainItem = AChainItem;
|
||||
class ChainItem extends AChainItem {
|
||||
class ABaseChainItem extends AChainItem {
|
||||
constructor(label) {
|
||||
super(label);
|
||||
}
|
||||
toString() {
|
||||
let funcName = (this._chainItemFunc.name === "") ? "lambda" : this._chainItemFunc.name;
|
||||
return `<${funcName}, ${this._label}>`;
|
||||
}
|
||||
registerFunc(func) {
|
||||
this._chainItemFunc = func;
|
||||
}
|
||||
begin() {
|
||||
if (this._next != null) {
|
||||
this._next.begin();
|
||||
}
|
||||
this.addListener('yourturn', (message) => {
|
||||
log.info(`Calling ${this.toString()}`);
|
||||
let result = this._chainItemFunc(message);
|
||||
if (this._next == null) {
|
||||
log.info(`Last chain item, final result ${result}`);
|
||||
}
|
||||
else {
|
||||
this._next.send(result);
|
||||
}
|
||||
let result = this.func(message);
|
||||
this._next.send(result);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ABaseChainItem = ABaseChainItem;
|
||||
class ChainItem extends ABaseChainItem {
|
||||
toString() {
|
||||
let funcName = (this._chainItemFunc.name === "") ? "lambda" : this._chainItemFunc.name;
|
||||
return `<${funcName}, ${this._label}>`;
|
||||
}
|
||||
registerFunc(func) {
|
||||
this._chainItemFunc = func;
|
||||
}
|
||||
func(message) {
|
||||
return this._chainItemFunc(message);
|
||||
}
|
||||
}
|
||||
exports.ChainItem = ChainItem;
|
||||
//# sourceMappingURL=callchain.js.map
|
Reference in New Issue
Block a user