Last active
March 29, 2020 00:42
-
-
Save Ric-Lavers/37a6d2c4e4d160b4b859514407b528ba 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 carDoorMachine = Machine({ | |
id: "carDoor", | |
initial: "idle", | |
context: { | |
isOpen: true, | |
}, | |
states: { | |
idle: { | |
on: { | |
DOWN_BUTTON_PRESSED: { | |
target: "lowering", | |
actions: assign(context => ({ ...context, isOpen: "pending" })), | |
cond: ({ isOpen }) => isOpen || isOpen === "pending", | |
}, | |
UP_BUTTON_PRESSED: { | |
target: "rising", | |
actions: assign(context => ({ ...context, isOpen: "pending" })), | |
cond: ({ isOpen }) => !isOpen || isOpen === "pending", | |
}, | |
}, | |
}, | |
lowering: { | |
on: { | |
DOWN_BUTTON_PRESSED: { target: "idle" }, | |
UP_BUTTON_PRESSED: "rising", | |
}, | |
after: { | |
3000: { | |
target: "idle", | |
actions: assign(context => { | |
return { | |
...context, | |
isOpen: false, | |
} | |
}), | |
}, | |
}, | |
}, | |
rising: { | |
on: { | |
UP_BUTTON_PRESSED: { target: "idle" }, | |
DOWN_BUTTON_PRESSED: "lowering", | |
}, | |
after: { | |
3000: { | |
target: "idle", | |
actions: assign(context => { | |
return { | |
...context, | |
isOpen: true, | |
} | |
}), | |
}, | |
}, | |
}, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment