-
-
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.
Recursive persistence of invoked actors (#3743)
* Add PersistedState * behavior.at (WIP) * Use invoke action instead * Ensure that persisted state isn't lost * Allow machine.at(...) to take optional arg * Cleanup * Renaming * Fix types * No more arguments for .start() * Improve types/tests * Add input with loose types * Update packages/core/src/StateMachine.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Move input closer to the interpreter (#3803) * Update packages/core/src/types.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Remove UseMachineOptions (React) * Remove options from other libraries * Remove public usage of .at(...) in favor of { state: ... } * Remove .at() (mostly) * Lint * Remove input from this PR * Oops * Remove machine.at * Remove state * Use `machine.getPersistedState` * public preInitialState -> private _preInitialState * Remove _preInitialState * Clarifying comment * getPersistedState should use initial state * Use .js at the end * start returns void * Add todo * Lint * Attempt to fix types * Ugh types * Address comments * Add changeset * Update .changeset/shy-cobras-ring.md Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Remove constraint * Update packages/core/src/State.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Don't do the hacky thing * Renaming etc * Change PersistedMachineState children shape * Small tweaks * Change test, remove action unshifting for starting actors * Add skipped test * Do better here (PersistedMachineState) * Remove comment * Fix promise test * Fix everything * Add src * Fix types * Rename PersistedFrom -> PersistedStateFrom * Sigh, types * self != this * Add test case: initial state of a child is available before starting the parent * Apply suggestion * Update packages/core/src/StateNode.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Update packages/core/src/StateMachine.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Update packages/core/src/types.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Made the test work * fixed types * Initialize the `Interpreter`'s state eagerly (#3874) * Initialize the `Interpreter`'s state eagerly * Fixed parent assignment on children * remove what was supposed to be removed * pass parent to the spawner within assign * pass parent to the initial context factory * Reassign the old state after stopping the machine in React hooks * fixed things * fixed tests * move a comment back to its original place to minimize the diff * Remove `persisted: true` check * Do not restart a completed observable actor * Update packages/core/test/actor.test.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Update packages/core/test/actor.test.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Update packages/core/test/actor.test.ts Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> * Update packages/core/test/actor.test.ts * Add event observable test * Fix types * Change back * Add changeset * Add another changeset --------- Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
- Loading branch information
1 parent
2d25c9a
commit 30c561e
Showing
44 changed files
with
952 additions
and
484 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,24 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
Restoring persisted state is now done by passing the state into the `state: ...` property of the `interpret` options argument: | ||
|
||
```diff | ||
-interpret(machine).start(state); | ||
+interpret(machine, { state }).start(); | ||
``` | ||
|
||
The persisted state is obtained from an actor by calling `actor.getPersistedState()`: | ||
|
||
```ts | ||
const actor = interpret(machine).start(); | ||
|
||
const persistedState = actor.getPersistedState(); | ||
|
||
// ... | ||
|
||
const restoredActor = interpret(machine, { | ||
state: persistedState | ||
}).start(); | ||
``` |
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,10 @@ | ||
--- | ||
'xstate': major | ||
--- | ||
|
||
Invoked actors can now be deeply persisted and restored. When the persisted state of an actor is obtained via `actor.getPersistedState()`, the states of all invoked actors are also persisted, if possible. This state can be restored by passing the persisted state into the `state: ...` property of the `interpret` options argument: | ||
|
||
```diff | ||
-interpret(machine).start(state); | ||
+interpret(machine, { state }).start(); | ||
``` |
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,2 @@ | ||
--- | ||
--- |
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.