Skip to content

Instantly share code, notes, and snippets.

@cogell
Created December 14, 2020 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cogell/aaa9849e6f870eb48d7c96996dc2e329 to your computer and use it in GitHub Desktop.
Save cogell/aaa9849e6f870eb48d7c96996dc2e329 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)
// IGNORING
// - logged IN / OUT
const syncCommunitiesMachine = Machine({
id: "syncCommunitiesMachine",
initial: "lastFailed", // this right?
context: {
local: {
home: 0,
communities: []
},
lastSyncDate: new Date() // use real date
},
states: {
lastFailed: {
on: {
ADD_COMMUNITY: "merging",
APP_OPENED: "merging"
}
},
lastSuccess: {
on: {
ADD_COMMUNITY: "pushing",
APP_OPENED: "pulling"
}
},
merging: {
invoke: {
id: "merge",
src: async (context, event) => {
console.log("get upstream"); // on fail, fire event('FAIL')
console.log("reconcile upstream and local");
console.log("set upstream"); // on fail, fire event('FAIL')
return new Promise(resolve => setTimeout(() => resolve(), 1000));
},
onDone: {
target: "lastSuccess"
},
onError: {
target: "lastFailed"
}
}
},
pushing: {
on: {
SUCCEED: "lastSuccess",
FAIL: "lastFailed"
}
},
pulling: {
on: {
SUCCEED: "lastSuccess",
FAIL: "lastFailed"
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment