Last active
June 20, 2020 14:37
-
-
Save knownasilya/e4e49b317ff01b9c07c4722720e608a4 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({ | |
id: 'entity', | |
initial: 'idle', | |
on: { | |
SAVE: 'saving' | |
}, | |
states: { | |
idle: { | |
on: { | |
AUTO_SAVE: { | |
actions: [ | |
assign({ | |
autoSavePayload: (_context, event) => | |
event.payload | |
}), | |
actions.cancel('debounced-save'), | |
actions.send('SAVE', { | |
delay: 450, | |
id: 'debounced-save' | |
}) | |
] | |
}, | |
PUBLISH: 'publishing', | |
DELETE: 'deleted' | |
} | |
}, | |
saving: { | |
invoke: { | |
id: 'updateBranchContent', | |
src: 'updateBranchContent', | |
onDone: { | |
target: 'idle', | |
actions: assign({ | |
updateContentResult: (_context, event) => event.data | |
}) | |
}, | |
onError: { | |
target: 'savingFailed', | |
actions: [ | |
assign({ | |
updateContentError: (_context, event) => | |
event.data | |
}), | |
'showErrorNotification' | |
] | |
} | |
}, | |
on: { | |
SAVED: 'idle' | |
} | |
}, | |
savingFailed: { | |
on: { | |
RETRY: 'saving' | |
} | |
}, | |
publishing: { | |
invoke: { | |
id: 'publish', | |
src: 'publish', | |
onDone: { | |
actions: 'viewPublished' | |
}, | |
onError: 'publishFailed' | |
} | |
}, | |
publishFailed: { | |
on: { | |
RETRY: 'publishing' | |
} | |
}, | |
deleted: { | |
entry: ['deletePr', 'deleteRecord'], | |
type: 'final' | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment