simple-modbus
Version:
A simple library for working with Modbus with Typescript bindings.
42 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* This code is borrowed from Basarat Ali Syed from his Typescript Gitbook.
* Licensed under Creative Commons https://creativecommons.org/licenses/by/4.0/
*
* Passes through events as they happen. You will not get events from before you start listening
*/
var TypedEvent = /** @class */ (function () {
function TypedEvent() {
var _this = this;
this.listeners = [];
this.listenersOncer = [];
this.on = function (listener) {
_this.listeners.push(listener);
return {
dispose: function () { return _this.off(listener); }
};
};
this.once = function (listener) {
_this.listenersOncer.push(listener);
};
this.off = function (listener) {
var callbackIndex = _this.listeners.indexOf(listener);
if (callbackIndex > -1)
_this.listeners.splice(callbackIndex, 1);
};
this.emit = function (event) {
/** Update any general listeners */
_this.listeners.forEach(function (listener) { return listener(event); });
/** Clear the `once` queue */
_this.listenersOncer.forEach(function (listener) { return listener(event); });
_this.listenersOncer = [];
};
this.pipe = function (te) {
return _this.on(function (e) { return te.emit(e); });
};
}
return TypedEvent;
}());
exports.TypedEvent = TypedEvent;
//# sourceMappingURL=typed-event.js.map