Skip to content

Instantly share code, notes, and snippets.

@vuhrmeister
Last active August 16, 2019 06:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vuhrmeister/5b92daa9f19087f7d2a881826f260832 to your computer and use it in GitHub Desktop.
Save vuhrmeister/5b92daa9f19087f7d2a881826f260832 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const stopMachine = Machine({
id: 'stop',
initial: 'idle',
context: {
id: undefined
},
states: {
idle: {
on: {
START: 'pending',
STALL: 'stalled'
}
},
stalled: {
on: {
UNSTALL: 'idle'
}
},
pending: {
onEntry: sendParent(ctx => ({ type: 'STOP_PENDING', stopId: ctx.id })),
initial: 'pending',
states: {
pending: {
on: {
CANCEL: 'idle',
FILL_BILL_OF_LADING: 'fillingBillOfLading'
}
},
fillingBillOfLading: {
on: {
SAVE: 'billOfLadingFilled',
CANCEL: 'pending'
}
},
// TODO does it really make sense? Or is it UI sugar?
// TODO make it cancelable
billOfLadingFilled: {
after: {
// TODO 5000 or so
1000: {
target: 'completed'
}
}
}
}
},
canceled: {
onEntry: sendParent(ctx => ({ type: 'STOP_CANCELLED', stopId: ctx.id })),
on: {
'': 'idle'
}
},
completed: {
type: 'final',
onEntry: sendParent(ctx => ({ type: 'STOP_COMPLETED', stopId: ctx.id }))
},
// TODO feels like a hack
selected: {
type: 'history'
}
},
on: {
SELECT_STOP: {
// TODO feels like a hack
target: 'selected',
actions: sendParent(ctx => ({ type: 'SELECT_STOP', stopId: ctx.id }))
}
}
}, {
guards: {
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment