Skip to content

Instantly share code, notes, and snippets.

@filipemonteiroth
Created November 27, 2019 14:05
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 filipemonteiroth/453f95ece0ebdf582db250e47b8a4a1d to your computer and use it in GitHub Desktop.
Save filipemonteiroth/453f95ece0ebdf582db250e47b8a4a1d 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 fetchMachine = Machine(
{
initial: 'viewing',
context: {
editingRowKey: null,
},
states: {
viewing: {
on: {
ADD: 'adding',
EDIT: 'editing',
ENABLE_BULK: 'bulkEdit',
APPROVE: 'approving',
FOCUS_ADD: {actions: 'focusAddBox'},
},
},
approving: {
on: {
APPROVE_COMPLETE: 'viewing',
},
},
adding: {
on: {
ADD_COMPLETE: 'viewing',
},
},
editing: {
entry: 'assignRowKey',
exit: 'clearRowKey',
on: {
EDIT_COMPLETE: 'viewing',
},
},
bulkEdit: {
on: {
DISABLE_BULK: 'viewing',
SELECT_ORDER: {cond: 'isValidOrder', actions: 'selectOrder'},
TOGGLE_ALL: {cond: 'areValidOrders', actions: 'toggleAll'},
},
},
},
},
{
guards: {
isValidOrder: () => false,
areValidOrders: () => false,
},
actions: {
assignRowKey: assign({
editingRowKey: (_, e) => (e.type === 'EDIT' ? e.rowKey : null),
}),
clearRowKey: assign({editingRowKey: null}),
selectOrder: assign({}),
toggleAll: assign({}),
},
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment