Last active
May 28, 2021 01:16
-
-
Save msell/c4e819982b5a090d51b9aa8c59820e07 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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
const noMechanicsAssigned = (context, event) => { | |
return context.mechanicsAssigned < 1 | |
} | |
const caseMachine = Machine({ | |
id: 'case', | |
initial: 'open', | |
context: { | |
mechanicsAssigned: 0 | |
}, | |
states: { | |
open: { | |
initial: 'initial', | |
on: { | |
STALL: 'stalled', | |
RESOLVE: 'resolved', | |
DELTED: 'deleted' | |
}, | |
states: { | |
initial: { | |
on: { | |
ASSIGN_MRO: 'maintenance_requested', | |
} | |
}, | |
maintenance_requested: { | |
on: { | |
MECHANIC_ASSIGNED: { | |
target: 'assigned', | |
actions: assign({ | |
mechanicsAssigned: (context, event) => context.mechanicsAssigned + 1 | |
}) | |
} | |
} | |
}, | |
unknown: { | |
always: [ | |
{ | |
target: 'maintenance_requested', | |
cond: noMechanicsAssigned }, | |
{target: 'assigned'} | |
] | |
}, | |
assigned: { | |
on: { | |
MECHANIC_ASSIGNED: { | |
actions: assign({ | |
mechanicsAssigned: (context, event) => context.mechanicsAssigned + 1 | |
}) | |
}, | |
MECHANIC_DISMISSED: [ | |
{ | |
target: 'unknown', | |
actions: [assign({ | |
mechanicsAssigned: (context, event) => context.mechanicsAssigned - 1 | |
})] | |
} | |
] | |
} | |
}, | |
history: { | |
type: 'history' | |
} | |
} | |
}, | |
deleted: { | |
type: 'final' | |
}, | |
stalled: { | |
on: { | |
resume: 'open.history' | |
} | |
}, | |
resolved: { | |
type: 'final' | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment