Skip to content

Instantly share code, notes, and snippets.

@wildskyf
Last active September 24, 2019 07:29
Show Gist options
  • Save wildskyf/abc5a74ab6dbd6511dd11eeecdbc103e to your computer and use it in GitHub Desktop.
Save wildskyf/abc5a74ab6dbd6511dd11eeecdbc103e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz, machine for memo
// 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