@lite-fsm/core 2.0.0 → 2.0.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 +63 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# @lite-fsm/core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic runtime for `lite-fsm`: typed machine configs, `MachineManager`, effects, actor templates, snapshots, hydration, middleware contracts, and core TypeScript types.
|
|
4
|
+
|
|
5
|
+
Use this package when you want the FSM runtime without React or any UI dependency.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @lite-fsm/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For Immer-style reducers that mutate draft state, also install middleware:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @lite-fsm/middleware immer
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Example
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { MachineManager, createMachine, type FSMEvent } from "@lite-fsm/core";
|
|
23
|
+
|
|
24
|
+
type ToggleEvent = FSMEvent<"TOGGLE"> | FSMEvent<"RESET">;
|
|
25
|
+
|
|
26
|
+
const toggle = createMachine<ToggleEvent>({
|
|
27
|
+
config: {
|
|
28
|
+
OFF: { TOGGLE: "ON", RESET: "OFF" },
|
|
29
|
+
ON: { TOGGLE: "OFF", RESET: "OFF" },
|
|
30
|
+
},
|
|
31
|
+
initialState: "OFF",
|
|
32
|
+
initialContext: { count: 0 },
|
|
33
|
+
reducer: (slice, event, { nextState }) => ({
|
|
34
|
+
state: nextState,
|
|
35
|
+
context: {
|
|
36
|
+
count: event.type === "RESET" ? 0 : slice.context.count + 1,
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const manager = MachineManager({ toggle });
|
|
42
|
+
|
|
43
|
+
manager.transition({ type: "TOGGLE" });
|
|
44
|
+
|
|
45
|
+
console.log(manager.getState().toggle);
|
|
46
|
+
// { state: "ON", context: { count: 1 } }
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Main Exports
|
|
50
|
+
|
|
51
|
+
- `createMachine` - typed machine config factory.
|
|
52
|
+
- `MachineManager` - runtime store for coordinating multiple machines.
|
|
53
|
+
- `createEffect` - effect wrapper with `every` or `latest` semantics.
|
|
54
|
+
- `createConfig` and `createReducer` - helpers for reusable typed config and reducer definitions.
|
|
55
|
+
- `Machine` and `defineMachine` - standalone machine APIs.
|
|
56
|
+
- Snapshot and hydration types for `dehydrate()` / `hydrate()` workflows.
|
|
57
|
+
- Middleware, actor, event, state, and manager types.
|
|
58
|
+
|
|
59
|
+
## Documentation
|
|
60
|
+
|
|
61
|
+
- [Full documentation](https://alexandergureev.github.io/lite-fsm/)
|
|
62
|
+
- [Core package guide](https://alexandergureev.github.io/lite-fsm/packages/core)
|
|
63
|
+
- [Core API reference](https://alexandergureev.github.io/lite-fsm/api/core)
|