effect-machine 0.1.0 → 0.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 CHANGED
@@ -15,6 +15,10 @@ State machines eliminate entire categories of bugs:
15
15
 
16
16
  ```bash
17
17
  bun add effect-machine effect
18
+ # or
19
+ pnpm add effect-machine effect
20
+ # or
21
+ npm install effect-machine effect
18
22
  ```
19
23
 
20
24
  ## Quick Example
@@ -142,6 +146,15 @@ machine
142
146
  .spawn(MyState.Polling, ({ effects }) => effects.poll({ interval: "5 seconds" }));
143
147
  ```
144
148
 
149
+ `.task()` runs on entry and sends success/failure events:
150
+
151
+ ```ts
152
+ machine.task(State.Loading, ({ effects, state }) => effects.fetchData({ url: state.url }), {
153
+ onSuccess: (data) => MyEvent.Resolve({ data }),
154
+ onFailure: () => MyEvent.Reject,
155
+ });
156
+ ```
157
+
145
158
  ### Testing
146
159
 
147
160
  Test transitions without actors:
@@ -182,6 +195,7 @@ See the [primer](./primer/) for comprehensive documentation:
182
195
  | `.on(State.X, Event.Y, handler)` | Add transition |
183
196
  | `.reenter(State.X, Event.Y, handler)` | Force re-entry on same state |
184
197
  | `.spawn(State.X, handler)` | State-scoped effect |
198
+ | `.task(State.X, run, { onSuccess })` | State-scoped task |
185
199
  | `.background(handler)` | Machine-lifetime effect |
186
200
  | `.provide({ slot: impl })` | Provide implementations |
187
201
  | `.final(State.X)` | Mark final state |
@@ -214,6 +228,9 @@ See the [primer](./primer/) for comprehensive documentation:
214
228
  | `actor.matches(tag)` | Check state tag |
215
229
  | `actor.can(event)` | Can handle event? |
216
230
  | `actor.changes` | Stream of changes |
231
+ | `actor.waitFor(fn)` | Wait for match |
232
+ | `actor.awaitFinal` | Wait final state |
233
+ | `actor.sendAndWait` | Send + wait |
217
234
  | `actor.subscribe(fn)` | Sync callback |
218
235
 
219
236
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-machine",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/cevr/effect-machine.git"