@uuxxx/fsm 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +22 -16
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -32,7 +32,7 @@ type State = 'idle' | 'loading' | 'success' | 'error';
32
32
 
33
33
  const fsm = makeFsm({
34
34
  init: 'idle',
35
- states: ['idle', 'loading', 'success', 'error'] as State[],
35
+ states: ['idle', 'loading', 'success', 'error'],
36
36
  transitions: {
37
37
  start: {
38
38
  from: 'idle',
@@ -285,11 +285,13 @@ Plugin names must be unique — registering two plugins with the same name trigg
285
285
 
286
286
  ### History Plugin
287
287
 
288
- Tracks state history with pointer-based navigation.
288
+ Read-only state history tracking with pointer-based navigation.
289
+
290
+ `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))`).
289
291
 
290
292
  ```typescript
291
293
  import { makeFsm } from '@uuxxx/fsm';
292
- import { fsmHistoryPlugin } from '@uuxxx/fsm/history-plugin';
294
+ import { historyPlugin } from '@uuxxx/fsm-plugins/history';
293
295
 
294
296
  const fsm = makeFsm({
295
297
  init: 'a',
@@ -297,27 +299,31 @@ const fsm = makeFsm({
297
299
  transitions: {
298
300
  goto: { from: '*', to: (s: 'a' | 'b' | 'c') => s },
299
301
  },
300
- plugins: [fsmHistoryPlugin()],
302
+ plugins: [historyPlugin()],
301
303
  });
302
304
 
303
305
  fsm.goto('b');
304
306
  fsm.goto('c');
305
- fsm.history.get(); // ['a', 'b', 'c']
306
-
307
- fsm.history.back(1); // returns 'b'
308
- fsm.history.back(1); // returns 'a'
309
- fsm.history.forward(2); // returns 'c'
307
+ fsm.history.get(); // ['a', 'b', 'c'] (returns a copy)
308
+
309
+ fsm.history.back(1); // returns 'b' (pointer moved, FSM state unchanged)
310
+ fsm.history.current(); // 'b'
311
+ fsm.history.canBack(); // true
312
+ fsm.history.canForward(); // true
313
+ fsm.history.forward(1); // returns 'c'
314
+ fsm.goto(fsm.history.current()); // actually transition to 'c'
310
315
  ```
311
316
 
312
317
  #### History API
313
318
 
314
- | Method | Returns | Description |
315
- | ---------------------------- | ---------- | ---------------------------------------------------------------------------------- |
316
- | `fsm.history.get()` | `TState[]` | Full history array |
317
- | `fsm.history.back(steps)` | `TState` | Move pointer back by `steps`, returns the state at that position. Clamps to start |
318
- | `fsm.history.forward(steps)` | `TState` | Move pointer forward by `steps`, returns the state at that position. Clamps to end |
319
-
320
- > **Note:** `back()` and `forward()` move the internal history pointer and return the state at that position. They do **not** trigger a state transition on the FSM — use transition methods if you need to change the actual FSM state.
319
+ | Method | Returns | Description |
320
+ | ---------------------------- | ---------- | --------------------------------------------------------------------------------------------------------------- |
321
+ | `fsm.history.get()` | `TState[]` | Returns a copy of the full history array |
322
+ | `fsm.history.current()` | `TState` | Returns the state at the current pointer position |
323
+ | `fsm.history.back(steps)` | `TState` | Move pointer back by `steps`, returns the state at that position. Clamps to start. Ignores non-positive values |
324
+ | `fsm.history.forward(steps)` | `TState` | Move pointer forward by `steps`, returns the state at that position. Clamps to end. Ignores non-positive values |
325
+ | `fsm.history.canBack()` | `boolean` | Whether the pointer can move back (pointer > 0) |
326
+ | `fsm.history.canForward()` | `boolean` | Whether the pointer can move forward (pointer < end) |
321
327
 
322
328
  When a transition occurs, any forward history after the current pointer is discarded (like browser navigation).
323
329
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uuxxx/fsm",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Lightweight, type-safe finite state machine for TypeScript with plugin support and lifecycle hooks",
5
5
  "keywords": [
6
6
  "finite state machine",