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
| type Props = { | |
| load(): void, | |
| } | |
| type States = { | |
| mode: 'loading' | 'loaded' | 'errors', | |
| data: any, | |
| } | |
| const actions = { |
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
| import { Machine } from 'xstate' | |
| const Alarm = { | |
| Alarm: { | |
| initial: 'Ringing', | |
| on: { CANCEL: 'Idle' }, | |
| states: { | |
| Ringing: { | |
| on: { SNOOZE: 'Snoozing' }, | |
| onEntry: ['startRing'], | |
| onExit: ['stopRing'], |
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
| let currentState = 'Idle' | |
| const nextState = alarmMachine | |
| .transition(currentState, 'ALARM_TRIGGERED') | |
| nextState.value // 'Ringing' | |
| nextState.actions // ['ring'] | |
| nextState.events // ['SNOOZE', 'CANCEL'] |
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
| import { withStatechart } from 'react-automata' | |
| import alarmMachine from './alarmMachine' | |
| import AlarmClock from './components/AlarmClock' | |
| export default withStatechart(alarmMachine)(AlarmClock) |
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
| import { withStatechart } from 'react-automata' | |
| import alarmMachine from './alarmMachine' | |
| const AlarmClock = ({ machineState }) => ( | |
| <Clock ringing={machineState.value === 'Ringing'}/> | |
| ) | |
| export default withStatechart(alarmMachine)(AlarmClock) |
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
| import { State, withStatechart } from 'react-automata' | |
| import alarmMachine from './alarmMachine' | |
| const AlarmClock = () => ( | |
| <> | |
| <State value='Ringing'> | |
| <Clock ringing /> | |
| </State> | |
| <State value=['Idle', 'Snoozing']> | |
| <Clock /> |
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
| import { State, withStatechart } from 'react-automata' | |
| import alarmMachine from './alarmMachine' | |
| const AlarmClock = () => ( | |
| <State | |
| value='Ringing' | |
| render={(ringing) => ( | |
| <Clock ringing={ringing} /> | |
| )} | |
| /> |
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
| import { Action, withStatechart } from 'react-automata' | |
| import alarmMachine from './alarmMachine' | |
| const AlarmClock = () => ( | |
| <> | |
| <Action show='ring'> | |
| <Ringing /> | |
| </Action> | |
| <Clock /> | |
| </> |
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
| import { withStatechart } from 'react-automata' | |
| import alarmMachine from './alarmMachine' | |
| class AlarmClock extends React.Component { | |
| state = { | |
| ringing: false | |
| } | |
| startRing = () => { | |
| this.setState({ ringing: true }) | |
| } |
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
| import { Machine } from 'xstate' | |
| import { createStatefulMachine } from '@avaragado/xstateful' | |
| import alarmMachine from './alarmMachine' | |
| const alarm = createStatefulMachine({ | |
| machine: alarmMachine | |
| }) | |
| alarm.init() |