You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
✨ feat: effect and effectify returns Effected instead of generator
1. `effect` and its variants now returns an effected function instead of a generator function for consistency.
2. `effectify` now returns an `Effected` instance instead of a generator for consistency.
Copy file name to clipboardExpand all lines: README.md
+9-40Lines changed: 9 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -397,44 +397,12 @@ export interface Effect<
397
397
398
398
At runtime, only `name` and `payloads` are present, while `__returnType` serves purely at the type level to infer the effect’s return type.
399
399
400
-
Using `yield*` with a factory function created by `effect` (or its variants) yields an `Effect` object. The `effect` function itself can be simplified as follows:
To keep things simple, let’s remove the type signatures and focus on the structure:
400
+
Using `yield*` with a factory function created by `effect` (or its variants) yields an `Effect` object. To understand how it works, let’s take a look at a simplified version of the `effect` function (and its variants) in JavaScript:
433
401
434
402
```typescript
435
403
function effect(name) {
436
404
returnfunction* (...payloads) {
437
-
returnyield { name: name, payloads };
405
+
returnyield { name, payloads };
438
406
};
439
407
}
440
408
@@ -451,6 +419,8 @@ function dependency(name) {
451
419
}
452
420
```
453
421
422
+
While the actual implementation of `effect` is more complex and returns a factory function that produces an `Effected` instance (instead of a generator function), the fundamental concept remains the same.
423
+
454
424
The mechanism of `.runSync()` and `.runAsync()` is also straightforward. These methods iterate through the generator function, and when encountering an `Effect` object, invoke the corresponding handler registered by `.handle()`. They then either resume or terminate the generator with the value passed to `resume` or `terminate`. The actual implementation is more complex, but the concept remains consistent.
455
425
456
426
> [!NOTE]
@@ -539,7 +509,7 @@ When you hover over the `raise` variable, you’ll see its `Effect` type is wrap
This might look complex at first, but it simply wraps the `effect` function to make it generic. `effect("iterate")` returns a generic generator function, and we pass type arguments to specialize it, then call the function with a value to yield an Effect object.
654
+
This might look complex at first, but it simply wraps the `effect` function to make it generic. `effect("iterate")` returns a generic factory function that produces an `Effected` instance, and we pass type arguments to specialize it, then call the function with a value to yield an `Effect` object.
685
655
686
656
### Handling effects with another effected program
687
657
@@ -691,7 +661,7 @@ For example, consider the following program:
0 commit comments