Skip to content

Instantly share code, notes, and snippets.

@wuweiweiwu
Created April 17, 2020 21:25
Show Gist options
  • Save wuweiweiwu/592d511f93e096ee61063079646ede59 to your computer and use it in GitHub Desktop.
Save wuweiweiwu/592d511f93e096ee61063079646ede59 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const teamAssignmentMachine = Machine(
{
id: 'team-assignment',
initial: 'idle',
states: {
idle: {
on: {
START: {
target: 'assigning',
actions: ['setAreaId', 'setTeamId'],
},
},
},
assigning: {
on: {
SELECT_OBJECT: {
actions: ['selectObjectId'],
},
SAVE: 'saved',
},
},
saved: {
type: 'final',
},
},
},
{
actions: {
setAreaId: assign({
areaId: (context, event) => event.areaId,
}),
setTeamId: assign({
areaId: (context, event) => event.teamId,
}),
selectObjectId: assign({
objectIds: (context, event) => context.objectIds?.concat([event.objectId]),
}),
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment