Last active
January 25, 2021 22:56
-
-
Save parties/c1dd46bacda1b066deca3cbd52c3f4b9 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
Machine({ | |
id: 'Fleet Page API', | |
initial: 'idle', | |
context: { | |
dog: null, | |
schedule: null, | |
}, | |
states: { | |
idle: { | |
on: { | |
FETCH: 'loading', | |
FOCUS_REQUIREMENT: 'focused', | |
CALCULATE: 'calculating', | |
} | |
}, | |
// Requirement focused | |
focused: { | |
on: { | |
REASSIGN: 'reassigning', | |
UNASSIGN: 'unassigning', | |
} | |
}, | |
// recalculate fleet schedule | |
calculating: { | |
// async pattern here | |
}, | |
// reassign a requirement to a different vessel | |
reassigning: { | |
// async pattern here | |
}, | |
unassigning: { | |
// async pattern here | |
}, | |
loading: { | |
invoke: { | |
id: 'fetchDog', | |
src: (context, event) => fetch('https://dog.ceo/api/breeds/image/random') | |
.then(data => data.json()), | |
onDone: { | |
target: 'resolved', | |
actions: assign({ | |
dog: (_, event) => event.data | |
}) | |
}, | |
onError: 'rejected' | |
}, | |
on: { | |
CANCEL: 'idle' | |
} | |
}, | |
resolved: { | |
type: 'final' | |
}, | |
rejected: { | |
on: { | |
FETCH: 'loading' | |
} | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment