@uuxxx/fsm-plugins
v0.1.2
Published
Official plugins for @uuxxx/fsm
Maintainers
Readme
@uuxxx/fsm-plugins
Official plugins for @uuxxx/fsm.
Plugins can be imported from the main entry point or individually via sub-path exports:
import { historyPlugin } from '@uuxxx/fsm-plugins';
// or
import { historyPlugin } from '@uuxxx/fsm-plugins/history';History Plugin
Read-only state history tracking with pointer-based back/forward navigation.
back() and forward() move an internal pointer and return the state at that position — they do not change the FSM state. Use transition methods to actually navigate (e.g. fsm.goto(fsm.history.back(1))).
import { makeFsm } from '@uuxxx/fsm';
import { historyPlugin } from '@uuxxx/fsm-plugins/history';
const fsm = makeFsm({
init: 'a',
states: ['a', 'b', 'c'],
transitions: { goto: { from: '*', to: (s: 'a' | 'b' | 'c') => s } },
plugins: [historyPlugin()],
});
fsm.goto('b');
fsm.goto('c');
fsm.history.get(); // ['a', 'b', 'c']
fsm.history.back(1); // 'b' (pointer moved, FSM state unchanged)
fsm.history.canBack(); // true
fsm.history.current(); // 'b'
fsm.goto(fsm.history.current()); // actually transition to 'b'