Last active
March 30, 2020 16:14
-
-
Save pangratz/03e09d293c228c77ce8e4f83d6ab9b45 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 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