Skip to content

Instantly share code, notes, and snippets.

@faisalarbain
Last active July 30, 2020 14:50
Show Gist options
  • Select an option

  • Save faisalarbain/17d46f6ca9a80c26038cb890140e4be7 to your computer and use it in GitHub Desktop.

Select an option

Save faisalarbain/17d46f6ca9a80c26038cb890140e4be7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const taskMachine = Machine({
id: 'task',
initial: 'pending',
states: {
pending: {},
inProgress: {},
onHold: {},
submitted: {},
cancelled: {},
}
})
const requestMachine = Machine({
id: 'request',
initial: 'open',
context: {
retries: 0
},
states: {
open: {
initial: 'unassigned',
states: {
unassigned: {
on: {
assign: 'assigned'
}
},
assigned: {
on: {
reassign: 'assigned',
accept: '#request.accepted',
reject: '#request.cancelled.rejected'
}
}
},
on: {
cancel: 'cancelled.userRequest'
}
},
accepted: {
initial: 'pending',
states: {
onHold: {
on: {
release: 'pending',
}
},
pending: {
on: {
hold: 'onHold',
start: 'started'
}
},
started: { type: 'final' },
},
onDone: 'inProgress',
on: {
cancel: 'cancelled.userRequest'
}
},
inProgress: {
initial: 'working',
states: {
blocked: {
on:{
release: 'working',
}
},
working: {
on:{
block: 'blocked',
complete: 'completed'
}
},
completed: { type: 'final'}
},
onDone: 'submitted',
on: {
cancel: 'cancelled.userRequest'
}
},
cancelled: {
states: {
userRequest: { type: 'final' },
rejected: { type: 'final' }
}
},
submitted: {
type: 'final'
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment