@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.
- package/README.md +22 -16
- 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']
|
|
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
|
-
|
|
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 {
|
|
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: [
|
|
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.
|
|
309
|
-
fsm.history.
|
|
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[]` |
|
|
317
|
-
| `fsm.history.
|
|
318
|
-
| `fsm.history.
|
|
319
|
-
|
|
320
|
-
|
|
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
|
|