Last active
November 24, 2020 23:32
-
-
Save mattstrom/0def71e61f9c806ff9411267fdd1e593 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 machine = Machine({ | |
id: 'example', | |
context: { | |
modalState: 'closed', | |
menuState: 'closed', | |
cartStatus: 'empty', | |
intermediateStep: '' | |
}, | |
type: 'parallel', | |
states: { | |
loginState: { | |
initial: 'loggedOut', | |
states: { | |
loggedOut: { | |
on: { | |
LOGIN: 'intermediate', | |
JUMP: 'loggedIn' | |
} | |
}, | |
intermediate: { | |
on: { | |
'': { | |
target: 'loggedIn', | |
actions: [ | |
assign({ | |
intermediateStep: 'hit' | |
}) | |
] | |
} | |
} | |
}, | |
loggedIn: { | |
on: { | |
LOGOUT: 'loggedOut' | |
}, | |
type: 'parallel', | |
states: { | |
modal: { | |
initial: 'closed', | |
states: { | |
closed: { | |
entry: assign({ | |
modalState: 'closed' | |
}), | |
on: { | |
OPEN_MODAL: 'opened' | |
} | |
}, | |
opened: { | |
entry: assign({ | |
modalState: 'opened', | |
cartStatus: 'full' | |
}), | |
on: { | |
CLOSE_MODAL: 'closed', | |
CLOSE_MODAL_AND_EMPTY_CART: { | |
target: 'closed', | |
actions: [ | |
assign({ cartStatus: 'empty'}) | |
] | |
} | |
} | |
} | |
} | |
}, | |
menu: { | |
initial: 'closed', | |
states: { | |
closed: { | |
entry: assign({ | |
modalState: 'closed' | |
}), | |
on: { | |
OPEN_MENU: 'opened' | |
} | |
}, | |
opened: { | |
entry: assign({ | |
modalState: 'opened', | |
cartStatus: 'full' | |
}), | |
on: { | |
CLOSE_MENU: 'closed', | |
CLOSE_MENU_AND_EMPTY_CART: { | |
target: 'closed', | |
actions: [ | |
assign({ cartStatus: 'empty'}) | |
] | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment