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 lightBulbMachine = Machine({ | |
id: "house", | |
initial: "init", | |
states: { | |
init: { | |
entry: "spawnLightBulbs", | |
on: { | |
"": "lightsOn" | |
} | |
}, |
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 statusMachine = Machine({ | |
id: 'status-machine', | |
type: 'parallel', | |
states: { | |
polling: { | |
initial: 'loading', | |
states: { | |
loading: { | |
invoke: { | |
src: 'sparkRequest', |
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 fetchMachine = Machine({ | |
id: "spark-status-machine", | |
initial: "loading", | |
states: { | |
loading: { | |
invoke: { | |
src: "sparkRequest", | |
onDone: "success", | |
onError: "failure" | |
} |
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 sparkStatus = Machine({ | |
id: 'status-machine', | |
initial: 'setup', | |
context: { | |
sparkActor: null, | |
}, | |
states: { | |
setup: { | |
entry: 'spawnSparkStatusUpdater', | |
on: { |
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 wiseLoadingMachine = Machine({ | |
id: 'wiseLoadingMachine', | |
initial: 'idle', | |
context: { | |
region: null | |
}, | |
states: { | |
idle: { | |
on: { | |
setTab: 'settingTab' |
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
import { useMachine as useXStateMachine } from '@xstate/react'; | |
const getStateStat = (state: any): string => { | |
if (typeof state === 'string') { | |
return state; | |
} | |
if (Object.keys(state).length > 1) { | |
throw new Error('useMachine does not support emitting stats for parallel 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
import { useMachine } from '@xstate/react'; | |
import feedbackMachine from './feedbackMachine'; | |
const Feedback = () => { | |
const [current, send] = useMachine(feedbackMachine); | |
return ...; | |
}; |
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 |
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 feedbackMachine = Machine({ | |
id: "feedback", | |
initial: "idle", | |
states: { | |
idle: { | |
on: { | |
good: "thanks", | |
bad: "tellUsWhy" | |
} | |
}, |
NewerOlder