@doeixd/machine 1.0.3 → 1.1.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.
Files changed (37) hide show
  1. package/README.md +48 -0
  2. package/dist/cjs/development/core.js.map +1 -1
  3. package/dist/cjs/development/delegate.js +89 -0
  4. package/dist/cjs/development/delegate.js.map +7 -0
  5. package/dist/cjs/development/index.js +374 -158
  6. package/dist/cjs/development/index.js.map +4 -4
  7. package/dist/cjs/development/minimal.js +163 -0
  8. package/dist/cjs/development/minimal.js.map +7 -0
  9. package/dist/cjs/development/react.js.map +1 -1
  10. package/dist/cjs/production/delegate.js +1 -0
  11. package/dist/cjs/production/index.js +3 -3
  12. package/dist/cjs/production/minimal.js +1 -0
  13. package/dist/esm/development/core.js.map +1 -1
  14. package/dist/esm/development/delegate.js +68 -0
  15. package/dist/esm/development/delegate.js.map +7 -0
  16. package/dist/esm/development/index.js +380 -158
  17. package/dist/esm/development/index.js.map +4 -4
  18. package/dist/esm/development/minimal.js +140 -0
  19. package/dist/esm/development/minimal.js.map +7 -0
  20. package/dist/esm/development/react.js.map +1 -1
  21. package/dist/esm/production/delegate.js +1 -0
  22. package/dist/esm/production/index.js +3 -3
  23. package/dist/esm/production/minimal.js +1 -0
  24. package/dist/types/delegate.d.ts +101 -0
  25. package/dist/types/delegate.d.ts.map +1 -0
  26. package/dist/types/index.d.ts +3 -0
  27. package/dist/types/index.d.ts.map +1 -1
  28. package/dist/types/minimal.d.ts +95 -0
  29. package/dist/types/minimal.d.ts.map +1 -0
  30. package/dist/types/types.d.ts +63 -0
  31. package/dist/types/types.d.ts.map +1 -0
  32. package/package.json +25 -1
  33. package/src/delegate.ts +267 -0
  34. package/src/index.ts +13 -0
  35. package/src/middleware.ts +1049 -1050
  36. package/src/minimal.ts +269 -0
  37. package/src/types.ts +85 -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