Last active
November 29, 2019 09:30
-
-
Save happylinks/e962d7b847a9684e63614b8d0fc0a735 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 layerMachine = Machine( | |
| { | |
| id: 'layer', | |
| initial: 'idle', | |
| states: { | |
| idle: { | |
| on: { | |
| MOUSE_OVER: 'hovered', | |
| }, | |
| }, | |
| hovered: { | |
| on: { | |
| MOUSE_OUT: 'idle', | |
| MOUSE_DOWN: 'editing', | |
| }, | |
| }, | |
| editing: { | |
| on: { | |
| CLICK: 'focused', | |
| }, | |
| entry: ['hideLayer'], | |
| }, | |
| focused: { | |
| on: { | |
| /* ESCAPE: */ | |
| BLUR: [ | |
| { | |
| target: 'saving', | |
| cond: 'contentValid', | |
| actions: ['repositionLayer', 'showLayer', 'updateContent'], | |
| }, | |
| { target: 'idle' }, | |
| ], | |
| CHANGE: { | |
| actions: assign({ | |
| editorState: (context, event) => { | |
| if (event.type === 'CHANGE') { | |
| return (context.editorState = event.editorState); | |
| } else { | |
| return context.editorState; | |
| } | |
| }, | |
| }), | |
| }, | |
| }, | |
| entry: ['trackFocused'], | |
| }, | |
| saving: { | |
| invoke: { | |
| id: 'updateCopy', | |
| src: (context) => | |
| context.updateCopy(context.id, context.value), | |
| onDone: { | |
| target: 'success', | |
| }, | |
| onError: { | |
| target: 'failure', | |
| }, | |
| }, | |
| entry: ['trackSaved'], | |
| }, | |
| success: { | |
| on: { | |
| '': 'idle', | |
| }, | |
| }, | |
| failure: { | |
| on: { | |
| '': 'idle', | |
| }, | |
| }, | |
| }, | |
| }, | |
| { | |
| actions: { | |
| trackSaved: (context) => { | |
| context.trackEvent({ | |
| name: `CopyMode.Text.Saved`, | |
| }); | |
| }, | |
| trackFocused: (context) => { | |
| context.trackEvent({ | |
| name: `CopyMode.Text.Focused`, | |
| }); | |
| }, | |
| }, | |
| guards: { | |
| contentValid: (context) => { | |
| let editorContent = ''; // context.editorState | |
| context.content !== editorContent; | |
| }, | |
| }, | |
| }, | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment