-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v5] Allow guard objects to reference other guard objects (#4064)
* Allow a guard object to reference another guard object * Add TODO * Update packages/core/src/guards.ts * Update packages/core/test/stateIn.test.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Add changeset * Add more tests * Update .changeset/red-berries-occur.md Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Update packages/core/src/guards.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> --------- Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
- Loading branch information
1 parent
69dc9c1
commit 0478972
Showing
5 changed files
with
188 additions
and
19 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,30 @@ | ||
--- | ||
'xstate': patch | ||
--- | ||
|
||
Guard objects can now reference other guard objects: | ||
|
||
```ts | ||
const machine = createMachine( | ||
{ | ||
initial: 'home', | ||
states: { | ||
home: { | ||
on: { | ||
NEXT: { | ||
target: 'success', | ||
guard: 'hasSelection' | ||
} | ||
} | ||
}, | ||
success: {} | ||
} | ||
}, | ||
{ | ||
guards: { | ||
// `hasSelection` is a guard object that references the `stateIn` guard | ||
hasSelection: stateIn('selected') | ||
} | ||
} | ||
); | ||
``` |
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