Created
May 27, 2020 16:20
-
-
Save bfillmer/343d97ee81658d78a704e2b909a6de9d 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
const glanceMachine = Machine( | |
{ | |
id: 'glanceMachine', | |
initial: 'idle', | |
context: { | |
expanded: 'open', | |
criteria: {}, | |
stats: {}, | |
}, | |
states: { | |
idle: { | |
entry: ['clearStats'], | |
on: { | |
FETCH: { | |
target: 'pending', | |
cond: 'isExpanded', | |
}, | |
OPEN: { | |
actions: ['setExpandedOpen'], | |
target: 'pending' | |
} | |
}, | |
}, | |
pending: { | |
entry: ['setCriteria'], | |
invoke: { | |
src: () => null, | |
onDone: { | |
target: 'success', | |
actions: assign({ | |
stats: (_, event) => transformStats(event.data), | |
}), | |
}, | |
onError: { | |
target: 'failure', | |
}, | |
}, | |
}, | |
success: { | |
on: { | |
FETCH: { | |
target: 'pending', | |
cond: 'isExpanded', | |
}, | |
OPEN: { | |
target: 'pending', | |
actions: ['setExpandedOpen'], | |
}, | |
CLOSED: { | |
target: 'idle', | |
actions: ['setExpandedClosed'], | |
}, | |
}, | |
}, | |
failure: { | |
on: { | |
FETCH: { | |
target: 'pending', | |
cond: 'isExpanded', | |
}, | |
OPEN: { | |
target: 'pending', | |
actions: ['setExpandedOpen'], | |
}, | |
CLOSED: { | |
target: 'idle', | |
actions: ['setExpandedClosed'], | |
}, | |
}, | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
setCriteria: assign({ | |
criteria: (context, event) => ({ ...context.criteria, ...event.criteria }), | |
}), | |
setExpandedOpen: assign({ expanded: 'open' }), | |
setExpandedClosed: assign({ expanded: 'closed' }), | |
clearStats: assign({ stats: {} }), | |
}, | |
guards: { | |
isExpanded: context => context.expanded === 'open', | |
}, | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment