Created
November 27, 2019 14:05
-
-
Save filipemonteiroth/453f95ece0ebdf582db250e47b8a4a1d 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
// 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