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 AlarmMachine from './statefulAlarmMachine' | |
const Clock = () => ( | |
<AlarmMachine | |
render={({ extstate, setextstate }) => ( | |
<TimeDisplay time={extstate.time} /> | |
)} | |
/> | |
) |
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 AlarmMachine from './statefulAlarmMachine' | |
const Ringing = () => ( | |
<AlarmMachine cond={({ state, exstate )} => ( | |
state === 'Ringing' && exstate.ringCount < 5 | |
)}> | |
<PlayRinging /> | |
</AlarmMachine> | |
) |
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 { createStatefulMachine, Reducer } from '@avaragado/xstateful' | |
import alarmMachine from './alarmMachine' | |
const initialState = { | |
alarmTrigger: +new Date() + 10000 | |
} | |
const reducer = Reducer.map({ | |
alarmSet: Reducer.update(({ action, extstate }) => ({ | |
alarmTrigger: action.time, |
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 AlarmMachine from './statefulAlarmMachine' | |
const AlarmClock = () => ( | |
<> | |
<AlarmMachine.Activity is='startRing'> | |
<Ringing /> | |
</AlarmMachine.Activity> | |
<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
<AlarmMachine.Provider> | |
<> | |
<AlarmClock /> | |
<AlarmClock /> | |
<> | |
</AlarmMachine.Provider> |
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 { createReactMachine } from '@avaragado/xstateful-react' | |
import alarm from './statefulAlarmMachine' | |
const AlarmMachine = createReactMachine(alarm) | |
export default AlarmMachine |
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() |
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 { 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 { State, withStatechart } from 'react-automata' | |
import alarmMachine from './alarmMachine' | |
const AlarmClock = () => ( | |
<State | |
value='Ringing' | |
render={(ringing) => ( | |
<Clock ringing={ringing} /> | |
)} | |
/> |