Skip to content

Instantly share code, notes, and snippets.

@RafalFilipek
Created April 8, 2020 19:37
Show Gist options
  • Save RafalFilipek/1e2fede82790f10aa2978ef029f530d9 to your computer and use it in GitHub Desktop.
Save RafalFilipek/1e2fede82790f10aa2978ef029f530d9 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 fetchMachine = Machine(
{
strict: true,
initial: "initializing",
context: {
market: "B2C",
count: 0,
elements: [],
},
states: {
initializing: {
invoke: {
src: "fetchItems",
onDone: { target: "ready" },
},
},
ready: {
type: "parallel",
states: {
adding: {
initial: "idle",
states: {
idle: {
on: {
ADD_ITEM: {
target: "active",
},
},
},
active: {
invoke: {
src: "addItem",
onDone: { target: "idle" },
onError: { target: "idle" },
},
},
},
},
removing: {
initial: "idle",
states: {
idle: {
on: {
REMOVE_ITEM: {
target: "active",
},
},
},
active: {
invoke: {
src: "removeItem",
onDone: { target: "idle" },
onError: { target: "idle" },
},
},
},
},
refreshing: {
initial: "idle",
states: {
idle: {
on: {
REFRESH_ITEMS: {
target: "active",
},
},
},
active: {
invoke: {
src: "fetchItems",
onDone: { target: "idle" },
onError: { target: "idle" },
},
},
},
},
},
},
},
},
{
services: {
addItem: () => Promise.resolve({}),
removeItem: () => Promise.resolve({}),
fetchItems: () => Promise.resolve({}),
},
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment