Skip to content

Instantly share code, notes, and snippets.

@mittinatten
Last active February 24, 2021 09:07
Show Gist options
  • Select an option

  • Save mittinatten/e5cb5d35902a189ae4392c196477737c to your computer and use it in GitHub Desktop.

Select an option

Save mittinatten/e5cb5d35902a189ae4392c196477737c to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
initial: "Idle",
type: "parallel",
states: {
NewContributions: {
initial: "Idle",
states: {
Idle: {
on: {
UPDATE_NEWER_THAN_COUNT_DEBOUNCED: "DebounceCount",
UPDATE_NEWER_THAN_COUNT: "Counting",
},
},
DebounceCount: {
after: [{delay: 2000, target: "Counting"}], // CONFIG.UPDATE_COUNT_DEBOUNCE_TIME
on: {UPDATE_NEWER_THAN_COUNT: "Counting"},
},
Counting: {
invoke: {
src: "newerThanCountQuery",
onDone: [
{
target: "ContributionsAvailable",
actions: [assign({newerThanCount: (_, event) => event.data})],
cond: (_, event) => true,//event.data > 0,
},
{
actions: [assign({newerThanCount: (_, event) => event.data})],
target: "Idle",
},
],
},
},
ContributionsAvailable: {
on: {
UPDATE_NEWER_THAN_COUNT_DEBOUNCED: "DebounceCount",
UPDATE_NEWER_THAN_COUNT: "Counting",
},
},
},
},
FetchingFromTop: {
initial: "Idle",
id: "FetchingFromTop",
states: {
Idle: {
on: {
FETCH_CONTRIBUTIONS_FROM_TOP: "Fetching",
},
},
Fetching: {
intitial: "FetchingContributions",
states: {
FetchingContributions: {
invoke: {
// spinner
src: "fetchFromTop",
onDone: "UpdatingCount",
},
},
UpdatingCount: {
invoke: {
// disabled / hide
src: "newerThanCountQuery",
onDone: {
actions: [assign({newerThanCount: (_, event) => event.data})],
target: "#FetchingFromTop.Idle",
},
},
},
}
},
},
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment