Skip to content

Instantly share code, notes, and snippets.

@mittinatten
Last active June 18, 2021 07:25
Show Gist options
  • Select an option

  • Save mittinatten/4b72b1858ee402aab6bb3108ab56ed98 to your computer and use it in GitHub Desktop.

Select an option

Save mittinatten/4b72b1858ee402aab6bb3108ab56ed98 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const forwardMediaMachine = Machine(
{
initial: "Loading",
context: {
tags: []
},
states: {
Loading: {
invoke: {
src: "loadInitialData",
onDone: {
target: "Form",
actions: assign({ initialData: (_, event) => event.data }),
},
onError: {
target: "Error",
},
},
},
Form: {
on: {
ADD_TAG: {
actions: assign({ tags: []})
},
REMOVE_TAG: {
actions: assign({
tags: (context, event) => context.tags.filter((tag) => tag !== event.tag),
}),
},
SUBMIT: {
target: "Forwarding",
actions: assign({ selectedMediaIds: (_, event) => event.mediaIds})
},
},
},
Forwarding: {
invoke: {
src: "forwardMedia",
onDone: { target: "Done" },
onError: { target: "Error" },
},
},
Done: {
entry: "notifyDone",
type: "final",
},
Error: {
type: "final",
},
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment