Created
April 22, 2020 15:50
-
-
Save n8io/15d790f15cbaada009400a9d5ca07ac5 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
const State = { | |
GREEN: "GO", | |
OFFLINE: "OFFLINE", | |
RED: "STOP", | |
UNKNOWN: "UNKNOWN", | |
YELLOW: "YELLOW", | |
}; | |
const Event = { | |
CHANGE: "CHANGE", | |
MAINTENANCE_END: "MAINTENANCE_END", | |
MAINTENANCE_START: "MAINTENANCE_START", | |
OUTAGE: "OUTAGE", | |
RESTORED: "RESTORED", | |
}; | |
const Action = { | |
GREEN_ENTERED: "GREEN_ENTERED", | |
GREEN_EXITED: "GREEN_EXITED", | |
OFFLINE_ENTERED: "OFFLINE_ENTERED", | |
OFFLINE_EXITED: "OFFLINE_EXITED", | |
RED_ENTERED: "RED_ENTERED", | |
RED_EXITED: "RED_EXITED", | |
UNKNOWN_ENTERED: "UNKNOWN_ENTERED", | |
UNKNOWN_EXITED: "UNKNOWN_EXITED", | |
YELLOW_ENTERED: "YELLOW_ENTERED", | |
YELLOW_EXITED: "YELLOW_EXITED", | |
}; | |
const states = { | |
[State.GREEN]: { | |
entry: Action.GREEN_ENTERED, | |
exit: Action.GREEN_EXITED, | |
on: { | |
[Event.CHANGE]: State.YELLOW, | |
[Event.MAINTENANCE_START]: State.OFFLINE, | |
[Event.OUTAGE]: State.UNKNOWN, | |
}, | |
}, | |
[State.OFFLINE]: { | |
entry: Action.OFFLINE_ENTERED, | |
exit: Action.OFFLINE_EXITED, | |
on: { | |
[Event.MAINTENANCE_END]: State.RED, | |
}, | |
}, | |
[State.RED]: { | |
entry: Action.RED_ENTERED, | |
exit: Action.RED_EXITED, | |
on: { | |
[Event.CHANGE]: State.GREEN, | |
[Event.MAINTENANCE_START]: State.OFFLINE, | |
[Event.OUTAGE]: State.UNKNOWN, | |
}, | |
}, | |
[State.UNKNOWN]: { | |
entry: Action.UNKNOWN_ENTERED, | |
exit: Action.UNKNOWN_EXITED, | |
on: { | |
[Event.MAINTENANCE_START]: State.OFFLINE, | |
[Event.RESTORED]: State.RED, | |
}, | |
}, | |
[State.YELLOW]: { | |
entry: Action.YELLOW_ENTERED, | |
exit: Action.YELLOW_EXITED, | |
on: { | |
[Event.CHANGE]: State.RED, | |
[Event.MAINTENANCE_START]: State.OFFLINE, | |
[Event.OUTAGE]: State.UNKNOWN, | |
}, | |
}, | |
}; | |
const actionsMap = { | |
[Action.GREEN_ENTERED]: () => {}, | |
[Action.GREEN_EXITED]: () => {}, | |
[Action.OFFLINE_ENTERED]: () => {}, | |
[Action.OFFLINE_EXITED]: () => {}, | |
[Action.RED_ENTERED]: () => {}, | |
[Action.RED_EXITED]: () => {}, | |
[Action.UNKNOWN_ENTERED]: () => {}, | |
[Action.UNKNOWN_EXITED]: () => {}, | |
[Action.YELLOW_ENTERED]: () => {}, | |
[Action.YELLOW_EXITED]: () => {}, | |
}; | |
const fetchMachine = Machine( | |
{ | |
id: "stopLight", | |
initial: State.GREEN, | |
states, | |
}, | |
{ actions: actionsMap } | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment