Created
December 14, 2020 19:26
-
-
Save cogell/aaa9849e6f870eb48d7c96996dc2e329 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
// 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