Skip to content

Instantly share code, notes, and snippets.

@baeharam
Last active July 15, 2020 07: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 baeharam/8e282b20b01907eb00677c27fd9e1164 to your computer and use it in GitHub Desktop.
Save baeharam/8e282b20b01907eb00677c27fd9e1164 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const INACTIVE = '비활성화';
const ACTIVE = '활성화';
const DELETE_PENDING = '삭제로딩';
const DELETE_SUCCESS = '삭제성공';
const DELETE_FAILURE = '삭제실패';
// Events
const TYPE = '입력';
const DELETE = '삭제';
const isEqualToProductName = () => {}
const deleteProduct = () => {}
const deleteProductMachine = Machine(
{
id: 'deleteProductMachine',
initial: INACTIVE,
context: {
canDelete: false,
product: null,
},
states: {
[INACTIVE]: {
on: {
[TYPE]: [
{
cond: isEqualToProductName,
target: ACTIVE,
},
],
},
},
[ACTIVE]: {
on: {
[DELETE]: DELETE_PENDING,
[TYPE]: INACTIVE,
},
},
[DELETE_PENDING]: {
invoke: {
id: 'deleteProduct',
src: 'deleteProduct',
onDone: DELETE_SUCCESS,
onError: DELETE_FAILURE,
},
},
[DELETE_SUCCESS]: {},
[DELETE_FAILURE]: {
after: {
1500: ACTIVE,
},
},
},
},
{
guards: {
isEqualToProductName,
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment