"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFiniteStateMachine = exports.ObservableFiniteStateMachine = void 0;
const react_1 = require("react");
const structures_1 = require("@blackglory/structures");
const observable_hooks_1 = require("observable-hooks");
const use_force_update_1 = require("./use-force-update");
var structures_2 = require("@blackglory/structures");
Object.defineProperty(exports, "ObservableFiniteStateMachine", { enumerable: true, get: function () { return structures_2.ObservableFiniteStateMachine; } });
function useFiniteStateMachine(schema, initialState) {
    const forceUpdate = (0, use_force_update_1.useForceUpdate)();
    const fsm = (0, react_1.useMemo)(() => new structures_1.ObservableFiniteStateMachine(schema, initialState), [schema]);
    (0, observable_hooks_1.useSubscription)((0, observable_hooks_1.useObservable)(() => fsm.observeStateChanges(), [fsm]), forceUpdate);
    return fsm;
}
exports.useFiniteStateMachine = useFiniteStateMachine;
//# sourceMappingURL=use-finite-state-machine.js.map