controlled-machine 0.4.2 → 0.4.3

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 +31 -6
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # Controlled Machine
2
2
 
3
- Manage your React UI state cleanly.
4
-
5
- - Separate logic from UI
6
- - Declarative state transitions
7
- - Full TypeScript support
3
+ A controlled state machine with **internal state management**.
4
+ Machine owns **its own state**. Your component passes **external data**.
8
5
 
9
6
  ```bash
10
7
  npm install controlled-machine
8
+ # or
9
+ yarn add controlled-machine
10
+ # or
11
+ pnpm add controlled-machine
11
12
  ```
12
13
 
13
14
  ---
@@ -435,6 +436,30 @@ createMachine<{
435
436
  { when: ['isEnabled', 'canIncrement', (ctx) => !ctx.isLoading], do: ... }
436
437
  ```
437
438
 
439
+ ### Guard Utilities
440
+
441
+ Compose guards with `not`, `and`, `or`:
442
+
443
+ ```ts
444
+ import { createMachine, not, and, or } from 'controlled-machine'
445
+
446
+ // not() - negate a guard
447
+ { when: not('isDisabled'), do: 'handleClick' }
448
+ { when: not((ctx) => ctx.loading), do: 'submit' }
449
+
450
+ // and() - all guards must pass
451
+ { when: and(['hasValue', 'isValid']), do: 'submit' }
452
+
453
+ // or() - at least one guard must pass
454
+ { when: or(['isAdmin', 'hasPermission']), do: 'delete' }
455
+
456
+ // Nested composition
457
+ { when: not(or(['isLoading', 'isDisabled'])), do: 'handleClick' }
458
+
459
+ // Mixed named and inline guards
460
+ { when: and(['hasValue', (ctx) => ctx.count > 0]), do: 'action' }
461
+ ```
462
+
438
463
  ---
439
464
 
440
465
  ## Computed Values
@@ -695,7 +720,7 @@ createMachine<{
695
720
  ### Exports
696
721
 
697
722
  ```ts
698
- import { createMachine, effect } from 'controlled-machine'
723
+ import { createMachine, effect, not, and, or } from 'controlled-machine'
699
724
  import { useMachine } from 'controlled-machine/react'
700
725
  import type {
701
726
  MachineTypes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "controlled-machine",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "A controlled state machine where state lives outside the machine",
5
5
  "type": "module",
6
6
  "sideEffects": false,