Skip to content

Instantly share code, notes, and snippets.

@pangratz
Last active March 30, 2020 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pangratz/03e09d293c228c77ce8e4f83d6ab9b45 to your computer and use it in GitHub Desktop.
Save pangratz/03e09d293c228c77ce8e4f83d6ab9b45 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({
id: 'fetch',
initial: 'active',
context: {
past: [],
current: null,
queue: [1, 2, 3]
},
states: {
active: {
type: "parallel",
states: {
past: {
initial: "empty",
states: {
empty: {},
filled: {}
}
},
current: {
initial: "empty",
states: {
empty: {},
filled: {
on: {
MOVE: {
target: "empty",
actions: assign({
current: null,
past: context => [...context.past, context.current]
}),
cond: "hasCurrent"
}
}
}
}
},
queue: {
initial: "empty",
states: {
empty: {},
filled: {
on: {
MOVE: {
target: "empty",
actions: assign({
current: context => context.queued[0],
queued: context => context.queued.slice(1)
}),
cond: "hasNext"
}
}
}
}
}
}
}
}
}, {
guards: {
hasCurrent: context => !!context.current,
hasNext: context => context.queue.length > 0
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment