'use strict'; var solidJs = require('solid-js'); // src/index.ts var EQUALS_OPTIONS = { equals: (a, b) => a.type === b.type }; function createMachine(options) { const { states, initial } = options, to = (type, value) => { setPayload({ type, value, to }); }, [payload, setPayload] = solidJs.createSignal( typeof initial === "object" ? { type: initial.type, value: initial.input, to } : { type: initial, value: void 0, to }, EQUALS_OPTIONS ); for (const key of Object.keys(states)) { to[key] = (input) => to(key, input); } const memo = solidJs.createMemo(() => { const next = payload(); next.value = solidJs.untrack(() => states[next.type](next.value, to)); return next; }); Object.defineProperties(memo, { type: { get: () => memo().type }, value: { get: () => memo().value }, to: { value: to } }); return memo; } exports.createMachine = createMachine;