Last active
June 9, 2020 18:40
-
-
Save FeliciousX/1383e0572830b65225562bcc6a8d37cb 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 editingVisualState = { | |
initial: 'loading', | |
states: { | |
loading: { | |
after: { | |
3000: [ | |
{ target: 'idle' } | |
] | |
} | |
}, | |
idle: { | |
on: { | |
save: 'saving', | |
preview: 'preview_mode', | |
comment: 'comment_mode' | |
} | |
}, | |
saving: { | |
on: { | |
saveDone: 'idle' | |
} | |
}, | |
preview_mode: { | |
on: { | |
exit: 'idle' | |
} | |
}, | |
comment_mode: { | |
on: { | |
exit: 'idle' | |
} | |
} | |
} | |
} | |
const editingTemplateState = { | |
initial: 'loading', | |
states: { | |
loading: { | |
after: { | |
3000: [ | |
{ target: 'editing' } | |
] | |
} | |
}, | |
editing: { | |
on: { | |
save: 'saving', | |
preview: 'preview_mode' | |
} | |
}, | |
saving: { | |
on: { | |
saveDone: 'saved' | |
} | |
}, | |
preview_mode: { | |
on: { | |
exit: 'editing' | |
} | |
}, | |
saved: { | |
type: 'final' | |
} | |
} | |
} | |
const editorMachine = Machine({ | |
initial: 'loading', | |
context: { | |
visualId: null, | |
templateId: '172' | |
}, | |
states: { | |
loading: { | |
after: { | |
3000: [ | |
{ target: 'editing_template', cond: 'isTemplate' }, | |
{ target: 'editing_visual', cond: 'isVisual' } | |
] | |
} | |
}, | |
editing_visual: { | |
...editingVisualState | |
}, | |
editing_template: { | |
onDone: 'editing_visual.idle', | |
...editingTemplateState | |
} | |
} | |
}, { | |
guards: { | |
isTemplate: (context, event) => { | |
return context.templateId !== null | |
}, | |
isVisual: (context, event) => { | |
return context.visualId !== null | |
} | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment