-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Add emit support for all actor logic creators (#4935)
* Add emit support for all actor logic creators * Add test for restored root actor * Update .changeset/smooth-crabs-dress.md Co-authored-by: with-heart <[email protected]> --------- Co-authored-by: with-heart <[email protected]>
- Loading branch information
1 parent
417f35a
commit 2ac08b7
Showing
6 changed files
with
386 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
All actor logic creators now support [emitting events](https://stately.ai/docs/event-emitter): | ||
|
||
**Promise actors** | ||
|
||
```ts | ||
const logic = fromPromise(async ({ emit }) => { | ||
// ... | ||
emit({ | ||
type: 'emitted', | ||
msg: 'hello' | ||
}); | ||
// ... | ||
}); | ||
``` | ||
|
||
**Transition actors** | ||
|
||
```ts | ||
const logic = fromTransition((state, event, { emit }) => { | ||
// ... | ||
emit({ | ||
type: 'emitted', | ||
msg: 'hello' | ||
}); | ||
// ... | ||
return state; | ||
}, {}); | ||
``` | ||
|
||
**Observable actors** | ||
|
||
```ts | ||
const logic = fromObservable(({ emit }) => { | ||
// ... | ||
|
||
emit({ | ||
type: 'emitted', | ||
msg: 'hello' | ||
}); | ||
|
||
// ... | ||
}); | ||
``` | ||
|
||
**Callback actors** | ||
|
||
```ts | ||
const logic = fromCallback(({ emit }) => { | ||
// ... | ||
emit({ | ||
type: 'emitted', | ||
msg: 'hello' | ||
}); | ||
// ... | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.