Skip to content

Instantly share code, notes, and snippets.

View christiannwamba's full-sized avatar

Christian Nwamba christiannwamba

  • AWS
  • Lagos, Nigeria
View GitHub Profile
version: '3.6'
services:
postgres:
image: postgres:12
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgrespassword
graphql-engine:
// DEMO: General demo with light bulp
// - Context
// - Actions
// -- Transitions
// -- Exit and Entry
// - States
// - Assign
// - Services https://codesandbox.io/s/xstate--bulb-demo-gkqrx?file=/src/index.js
// Available variables:
// DEMO: Hierarchical + Parallel States
const heatedStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
}
}
// DEMO: Internal Transitions
const idleMachine = Machine(
{
id: "idle",
initial: "idle",
states: {
idle: {
entry: ["logEntry"],
exit: ["logExit"]
// DEMO: Calling events from other events
const echoMachine = Machine({
id: "echo",
initial: "listening",
states: {
listening: {
on: {
SPEAK: {
// Calls the ECHO action
// DEMO: Side effects with activities
// Look for beebing in the console
const initial = "idle";
const states = {
idle: {
on: {
ALARM: "alarming"
}
},
// DEMO: Guarding
const vendingMachineMachine = Machine(
{
id: "vendingMachine",
initial: "idle",
context: {
deposited: 0
},
states: {
// DEMO: History State (Shallow)
const poweredOnStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
},
// DEMO: History State Deep
const heatedStates = {
lowHeat: {
on: { TOGGLE_HEAT: 'highHeat' }
},
highHeat: {
on: { TOGGLE_HEAT: 'lowHeat' }
}
}
// DEMO: Null or Transient Transitions with ''
// Cick TRY 3 times and it will get to success but will keep coming back to idle at 1 and 2 time
// You can see the state increment in the STATE tab when you click TRY
const ifAtFirstYouDontSucceed = Machine(
{
id: 'tryTryAgain',
initial: 'idle',
context: {
tries: 0,