fsmachine
Version:
> A simple and small TypeScript finite state machine
38 lines • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMachineAsync = exports.createMachine = void 0;
const dispatch_1 = require("./dispatch");
const transition_1 = require("./transition");
function createMachine(init, opts = {}) {
const { transition, transitions } = transition_1.transitioner(opts.name);
const create = (override) => {
var _a;
return dispatch_1.dispatcher((_a = override === null || override === void 0 ? void 0 : override.init) !== null && _a !== void 0 ? _a : init, transitions, override !== null && override !== void 0 ? override : opts);
};
const machine = {
transition: (...ts) => {
transition(...ts);
return machine;
},
create,
};
return machine;
}
exports.createMachine = createMachine;
function createMachineAsync(init, opts = {}) {
const { transition, transitions } = transition_1.transitioner(opts.name);
const create = (override) => {
var _a;
return dispatch_1.dispatcherAsync((_a = override === null || override === void 0 ? void 0 : override.init) !== null && _a !== void 0 ? _a : init, transitions, override !== null && override !== void 0 ? override : opts);
};
const machine = {
transition: (...ts) => {
transition(...ts);
return machine;
},
create,
};
return { transition, create };
}
exports.createMachineAsync = createMachineAsync;
//# sourceMappingURL=machine.js.map