fsmachine
Version:
> A simple and small TypeScript finite state machine
21 lines • 804 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.transitioner = void 0;
function transitioner(name) {
const transitions = new Map();
const transition = (...transition) => {
for (const [from, ev, to, cb] of transition) {
if (!transitions.has(ev))
transitions.set(ev, new Map());
const fromMap = transitions.get(ev);
if (fromMap.has(from)) {
throw new Error(`Handler already set for ${name}::${from} --> ${to}`);
}
fromMap.set(from, { to, cb: cb !== null && cb !== void 0 ? cb : noop });
}
};
return { transitions, transition };
}
exports.transitioner = transitioner;
function noop() { }
//# sourceMappingURL=transition.js.map