Last active
September 24, 2019 07:29
Generated by XState Viz: https://xstate.js.org/viz, machine for memo
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) | |
const memoMachine = Machine({ | |
id: 'memo', | |
initial: 'idle', | |
context: { | |
changed: false | |
}, | |
states: { | |
idle: { | |
on: { | |
click: 'focused' | |
} | |
}, | |
focused: { | |
id: 'focused', | |
on: { | |
typing: 'typing', | |
}, | |
after: { | |
300: { | |
target: 'saving', | |
cond: 'shouldSave' | |
} | |
} | |
}, | |
typing: { | |
on: { | |
stop: { | |
target: 'focused', | |
actions: assign({ | |
changed: true | |
}) | |
} | |
} | |
}, | |
saving: { | |
type: 'parallel', | |
states: { | |
_: { | |
initial: 'hi', | |
states: { | |
hi: { | |
on: { | |
done: { | |
target: '#focused', | |
actions: assign({ | |
changed: false | |
}) | |
} | |
} | |
} | |
} | |
}, | |
show_message: { | |
initial: 'showing', | |
states: { | |
showing: { | |
meta: { | |
message: 'saved' | |
}, | |
after: { | |
2000: 'hide' | |
} | |
}, | |
hide: { | |
type: 'final' | |
} | |
} | |
} | |
} | |
} | |
} | |
}, { | |
guards: { | |
'shouldSave': (s, eve) => s.changed | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment