Last active
April 21, 2021 05:41
-
-
Save Krutie/c9a0e82b422e164c27414a6be1c5e194 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// TRAFFIC-LIGHT MACHINE | |
// =================== | |
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const alertsMachine = Machine({ | |
id: 'alerts', | |
initial: 'green', | |
context: { | |
yellowRetries: 0, | |
redRetries: 0, | |
greenRetries: 0 | |
}, | |
states: { | |
green: { | |
on: { | |
// WARN: 'yellow', | |
WARN: { | |
target: 'yellow', | |
actions: assign({ | |
yellowRetries: (context, event) => | |
context.yellowRetries + 1 | |
}) | |
}, | |
PANIC: { | |
target: 'red', | |
actions: assign({ | |
redRetries: (context, event) => context.redRetries + 1 | |
}) | |
} | |
} | |
}, | |
yellow: { | |
on: { | |
PANIC: { | |
target: 'red', | |
actions: assign({ | |
redRetries: (context, event) => context.redRetries + 1 | |
}) | |
}, | |
CLEAR: { | |
target: 'green', | |
actions: assign({ | |
greenRetries: (context, event) => context.greenRetries + 1 | |
}) | |
} | |
} | |
}, | |
red: { | |
on: { | |
CALM: { | |
target: 'yellow', | |
actions: assign({ | |
yellowRetries: (context, event) => | |
context.yellowRetries + 1 | |
}) | |
}, | |
CLEAR: { | |
target: 'success', | |
actions: assign({ | |
greenRetries: (context, event) => context.greenRetries + 1 | |
}) | |
} | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment