Created
July 17, 2019 01:42
-
-
Save isaacplmann/f854330868056d9c83500755c637c110 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
const fetchDataMachine = Machine({ | |
id: 'fetchData', | |
context: { data: undefined }, | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { FETCH: 'pending'} | |
}, | |
pending: { | |
on: { | |
RESOLVE: 'fulfilled', | |
REJECT: 'rejected' | |
} | |
}, | |
fulfilled: { | |
onEntry: assign({ | |
data: (ctx, event) => event.data | |
}), | |
onExit: assign({ | |
data: () => undefined | |
}), | |
on: { | |
REFRESH: 'pending' | |
}, | |
initial: 'unknown', | |
states: { | |
unknown: { | |
on: { | |
'': [ | |
{ target: 'withData', cond: 'hasData' }, | |
{ target: 'withoutData' }, | |
] | |
} | |
}, | |
withData: {}, | |
withoutData: {} | |
} | |
}, | |
rejected: { | |
on: { | |
RETRY: 'pending' | |
} | |
} | |
} | |
}, { | |
guards: { | |
hasData: (ctx, event) => ctx.data && ctx.data.length > 0 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment