Created
December 30, 2021 23:44
-
-
Save Andarist/812dc699e7161ba31887af2d19e7b997 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 createSingleState = () => ({ | |
initial: "fetch", | |
states: { | |
fetch: { | |
invoke: { | |
src: "fetchSmth", | |
onDone: { | |
target: "done", | |
actions: "notifySingleSuccess" | |
} | |
} | |
}, | |
done: { | |
type: "final" | |
} | |
} | |
}); | |
const testMachine = Machine( | |
{ | |
id: "test", | |
type: "parallel", | |
onDone: { | |
actions: "notifyBothSuccess" | |
}, | |
states: { | |
first: createSingleState(), | |
second: createSingleState() | |
} | |
}, | |
{ | |
actions: { | |
notifySingleSuccess: () => console.log(Date.now(), "single success"), | |
notifyBothSuccess: () => console.log(Date.now(), "both success") | |
}, | |
services: { | |
fetchSmth: () => { | |
const ms = Math.floor(Math.random() * 1000); | |
console.log("gonna resolve in", ms); | |
return new Promise(resolve => | |
setTimeout(() => { | |
console.log(Date.now(), "resolving single"); | |
resolve(); | |
}, ms) | |
); | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment