Created
July 27, 2021 22:21
-
-
Save schpet/2e1c9028cf122b12b76859063deeb3f6 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine({ | |
id: "animation", | |
initial: "pending", | |
context: { | |
staleUsers: null, | |
currentUsers: null, | |
}, | |
states: { | |
// loading the stale list is an async operation | |
pending: { | |
invoke: { | |
src: "readStaleList", | |
onDone: { | |
target: "staleListLoaded", | |
actions: assign({ | |
staleUsers: (_context, event) => event.data, | |
}), | |
}, | |
}, | |
}, | |
// while we wait for the new list of users to come in, | |
// we show the stale list | |
staleListLoaded: { | |
on: { | |
UPDATE_CURRENT_USERS: { | |
target: "animatingStaleListOut", | |
actions: assign({ | |
currentUsers: (_ctx, event) => event.users, | |
}), | |
}, | |
}, | |
}, | |
// fade out people not in new list, move the people to their new positions | |
animatingStaleListOut: { | |
invoke: { | |
src: "animateStaleOut", | |
onDone: { | |
target: "animatingCurrentListIn", | |
}, | |
}, | |
}, | |
animatingCurrentListIn: { | |
invoke: [ | |
{ src: "animateCurrentIn", onDone: "static" }, | |
{ src: "persistCurrentListAsStale" }, | |
], | |
}, | |
// change state so that stale and current are equal, this should | |
// not trigger an animation | |
static: { | |
on: { | |
UPDATE_CURRENT_USERS: { | |
target: "animatingStaleListOut", | |
actions: assign({ | |
staleUsers: (ctx) => ctx.currentUsers, | |
currentUsers: (_ctx, event) => event.users, | |
}), | |
}, | |
}, | |
}, | |
}, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment