Last active
May 13, 2021 11:27
-
-
Save DVG/e2ad8d6c976e495e7d083e1799c091f2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const objectiveApiMachine = Machine({ | |
id: 'api', | |
initial: 'idle', | |
context: { | |
objectives: [] | |
}, | |
states: { | |
idle: { | |
on: { | |
LOAD: 'loading', | |
NEW: 'create' | |
} | |
}, | |
loading: { | |
on: { | |
SUCCESS: { | |
target: 'idle', | |
actions: assign({ | |
objectives: (context, event) => [ | |
{ id: 1 }, | |
{ id: 2 } | |
]}) | |
} | |
} | |
}, | |
create: { | |
on: { | |
SUCCESS: { | |
target: 'idle', | |
actions: assign({ | |
objectives: (context, event) => [ | |
...context.objectives, | |
{ id: 4 } | |
] | |
}) | |
}, | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment