Created
March 19, 2021 18:47
-
-
Save bwaidelich/7354578ebb99b997544919c3e1730a68 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
const myMachine = Machine({ | |
id: "machine", | |
initial: "idle", | |
context: { | |
id: null, | |
revision: 0, | |
isOwner: false, | |
isAuthenticated: true | |
}, | |
states: { | |
idle: { | |
on: { | |
CHANGE: "pendingChanges", | |
LOAD: "loading", | |
}, | |
}, | |
pendingChanges: { | |
on: { | |
CHANGE: { target: "pendingChanges", internal: true }, | |
SAVE: [ | |
{ | |
target: 'saving', | |
cond: "isOwner", | |
actions: "createRevision" | |
}, | |
{ | |
target: 'choosingPod', | |
cond: "isAuthenticated" | |
}, | |
{target: 'saving'} | |
] | |
}, | |
}, | |
saving: { | |
invoke: { | |
id: 'saving', | |
src: "save", | |
onDone: { | |
target: 'idle', | |
actions: assign({ isOwner: (context, event) => true }) | |
}, | |
onError: { | |
target: 'error' | |
} | |
} | |
}, | |
loading: { | |
invoke: { | |
id: 'loading', | |
src: "load", | |
onDone: { | |
target: 'idle', | |
actions: assign({ isOwner: (context, event) => true }) | |
}, | |
onError: { | |
target: 'error' | |
} | |
} | |
}, | |
choosingPod: { | |
on: { | |
CHOOSE: "saving", | |
} | |
}, | |
error: {} | |
}, | |
}, { | |
guards: { | |
isAuthenticated: (context, event) => context.isAuthenticated, | |
isOwner: (context, event) => context.isOwner, | |
}, | |
actions: { | |
}, | |
services: { | |
save: () => true, | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment