@doeixd/machine 1.0.3 → 1.2.0
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 +48 -0
- package/dist/cjs/development/core.js.map +1 -1
- package/dist/cjs/development/delegate.js +89 -0
- package/dist/cjs/development/delegate.js.map +7 -0
- package/dist/cjs/development/index.js +383 -158
- package/dist/cjs/development/index.js.map +4 -4
- package/dist/cjs/development/minimal.js +172 -0
- package/dist/cjs/development/minimal.js.map +7 -0
- package/dist/cjs/development/react.js.map +1 -1
- package/dist/cjs/production/delegate.js +1 -0
- package/dist/cjs/production/index.js +3 -3
- package/dist/cjs/production/minimal.js +1 -0
- package/dist/esm/development/core.js.map +1 -1
- package/dist/esm/development/delegate.js +68 -0
- package/dist/esm/development/delegate.js.map +7 -0
- package/dist/esm/development/index.js +389 -158
- package/dist/esm/development/index.js.map +4 -4
- package/dist/esm/development/minimal.js +149 -0
- package/dist/esm/development/minimal.js.map +7 -0
- package/dist/esm/development/react.js.map +1 -1
- package/dist/esm/production/delegate.js +1 -0
- package/dist/esm/production/index.js +3 -3
- package/dist/esm/production/minimal.js +1 -0
- package/dist/types/delegate.d.ts +101 -0
- package/dist/types/delegate.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/minimal.d.ts +95 -0
- package/dist/types/minimal.d.ts.map +1 -0
- package/dist/types/types.d.ts +110 -0
- package/dist/types/types.d.ts.map +1 -0
- package/package.json +25 -1
- package/src/delegate.ts +267 -0
- package/src/index.ts +13 -0
- package/src/middleware.ts +1049 -1050
- package/src/minimal.ts +269 -0
- package/src/types.ts +129 -0
package/README.md
CHANGED
|
@@ -59,6 +59,7 @@ type Machine<C extends object> = {
|
|
|
59
59
|
**Flexibility**: Unlike rigid FSM implementations, you can choose your level of immutability. Want to mutate? You can. Want pure functions? You can. Want compile-time state validation? Type-State Programming gives you that.
|
|
60
60
|
|
|
61
61
|
**Read more about our core principles:** [ 📖 Core Principles Guide ](./docs/principles.md)
|
|
62
|
+
**Explore our utility helpers:** [ 🏷️ Tagged Helpers & Utilities ](./docs/tagged-helpers.md)
|
|
62
63
|
|
|
63
64
|
## Choosing the Right Pattern
|
|
64
65
|
|
|
@@ -2380,6 +2381,53 @@ createMultiMachine<C extends object, T extends MultiMachineBase<C>>(
|
|
|
2380
2381
|
): C & T
|
|
2381
2382
|
```
|
|
2382
2383
|
|
|
2384
|
+
|
|
2385
|
+
## 📦 Submodules
|
|
2386
|
+
|
|
2387
|
+
For specialized use cases, you can import from specific submodules to reduce bundle size or use advanced inference features:
|
|
2388
|
+
|
|
2389
|
+
- **`@doeixd/machine/minimal`**: Lightweight API with "magic" type inference. [📖
|
|
2390
|
+
Guide](./docs/minimal.md)
|
|
2391
|
+
- **`@doeixd/machine/delegate`**: Utilities for composing machines via delegation. [📖
|
|
2392
|
+
Guide](./docs/delegate.md)
|
|
2393
|
+
- **`@doeixd/machine/react`**: React integration (hooks and components).
|
|
2394
|
+
- **`@doeixd/machine/extract`**: Build-time statechart extraction tools.
|
|
2395
|
+
|
|
2396
|
+
## 🚀 Minimal API & Perfect Inference
|
|
2397
|
+
|
|
2398
|
+
The `@doeixd/machine/minimal` submodule is optimized for **Type-State Programming** with zero boilerplate. It features "magic" type inference, meaning you almost never have to write explicit generic types.
|
|
2399
|
+
|
|
2400
|
+
```typescript
|
|
2401
|
+
import { machine } from "@doeixd/machine/minimal";
|
|
2402
|
+
|
|
2403
|
+
// Transitions (inc, add) are automatically inferred!
|
|
2404
|
+
const counter = machine({ count: 0 }, (ctx, next) => ({
|
|
2405
|
+
inc: () => next({ count: ctx.count + 1 }),
|
|
2406
|
+
add: (n: number) => next({ count: ctx.count + n })
|
|
2407
|
+
}));
|
|
2408
|
+
|
|
2409
|
+
const result = counter.inc().add(10);
|
|
2410
|
+
console.log(result.count); // 11
|
|
2411
|
+
```
|
|
2412
|
+
|
|
2413
|
+
## 🤝 Machine Delegation
|
|
2414
|
+
|
|
2415
|
+
Use `@doeixd/machine/delegate` to compose complex machines by delegating transitions to child machines.
|
|
2416
|
+
|
|
2417
|
+
```typescript
|
|
2418
|
+
import { machine } from "@doeixd/machine/minimal";
|
|
2419
|
+
import { delegate } from "@doeixd/machine/delegate";
|
|
2420
|
+
|
|
2421
|
+
const authMachine = machine({ status: 'out' }, (ctx, next) => ({
|
|
2422
|
+
login: () => next({ status: 'in' })
|
|
2423
|
+
}));
|
|
2424
|
+
|
|
2425
|
+
const rootMachine = machine({ auth: authMachine }, (ctx, next) => ({
|
|
2426
|
+
// Automatically delegate 'login' to the 'auth' child!
|
|
2427
|
+
...delegate(ctx, 'auth', next)
|
|
2428
|
+
}));
|
|
2429
|
+
|
|
2430
|
+
|
|
2383
2431
|
## License
|
|
2384
2432
|
|
|
2385
2433
|
MIT
|