@botol/dipo
Version:
## Simple Composite controller
35 lines (34 loc) • 859 B
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dipo = void 0;
class Dipo {
constructor(events) {
this.events = events;
this.handlers = [];
}
addEvent(event, handler) {
this.events[event] = handler;
}
middleware(handler) {
this.handlers.push(handler);
return this;
}
on(event, handler) {
this.use(this.events[event](handler));
return this;
}
use(handler) {
this.handlers.push(handler);
return this;
}
handle(context) {
return this.next(context, 0);
}
next(context, i) {
if (i >= this.handlers.length) {
return;
}
return this.handlers[i](context, () => this.next.call(this, context, i + 1));
}
}
exports.Dipo = Dipo;