Skip to content

Instantly share code, notes, and snippets.

@dsadhanala
Created April 7, 2020 01:53
Show Gist options
  • Save dsadhanala/d35b5c36928d25c071827e684b5fa390 to your computer and use it in GitHub Desktop.
Save dsadhanala/d35b5c36928d25c071827e684b5fa390 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const HeaderMachine = Machine(
{
id: 'header',
strict: true,
initial: 'ready',
context: {
projectName: ''
},
states: {
ready: {
on: {
PROJECT_NAME_EDIT: 'editing'
}
},
editing: {
on: {
PROJECT_NAME_SAVING: 'saving',
PROJECT_NAME_CANCEL: 'cancelled'
}
},
saving: {
entry: ['updateLabel'],
after: [{ delay: 2000, target: 'saved' }],
on: {
PROJECT_NAME_SAVE: 'saved'
}
},
saved: {
on: { PROJECT_NAME_EDIT: 'editing' }
},
cancelled: {
on: { PROJECT_NAME_EDIT: 'editing' }
}
}
},
{ actions: { updateLabel: assign({ projectName: (_, event) => event.projectName }) } }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment