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
version: '3.6' | |
services: | |
postgres: | |
image: postgres:12 | |
restart: always | |
volumes: | |
- db_data:/var/lib/postgresql/data | |
environment: | |
POSTGRES_PASSWORD: postgrespassword | |
graphql-engine: |
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
// 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: |
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
// DEMO: Hierarchical + Parallel States | |
const heatedStates = { | |
lowHeat: { | |
on: { TOGGLE_HEAT: 'highHeat' } | |
}, | |
highHeat: { | |
on: { TOGGLE_HEAT: 'lowHeat' } | |
} | |
} |
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
// DEMO: Internal Transitions | |
const idleMachine = Machine( | |
{ | |
id: "idle", | |
initial: "idle", | |
states: { | |
idle: { | |
entry: ["logEntry"], | |
exit: ["logExit"] |
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
// DEMO: Calling events from other events | |
const echoMachine = Machine({ | |
id: "echo", | |
initial: "listening", | |
states: { | |
listening: { | |
on: { | |
SPEAK: { | |
// Calls the ECHO action |
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
// DEMO: Side effects with activities | |
// Look for beebing in the console | |
const initial = "idle"; | |
const states = { | |
idle: { | |
on: { | |
ALARM: "alarming" | |
} | |
}, |
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
// DEMO: Guarding | |
const vendingMachineMachine = Machine( | |
{ | |
id: "vendingMachine", | |
initial: "idle", | |
context: { | |
deposited: 0 | |
}, | |
states: { |
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
// DEMO: History State (Shallow) | |
const poweredOnStates = { | |
lowHeat: { | |
on: { TOGGLE_HEAT: 'highHeat' } | |
}, | |
highHeat: { | |
on: { TOGGLE_HEAT: 'lowHeat' } | |
}, |
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
// DEMO: History State Deep | |
const heatedStates = { | |
lowHeat: { | |
on: { TOGGLE_HEAT: 'highHeat' } | |
}, | |
highHeat: { | |
on: { TOGGLE_HEAT: 'lowHeat' } | |
} | |
} |
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
// 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, |