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
Machine({ | |
initial: 'playing', | |
context: { | |
plays: 0 | |
}, | |
states: { | |
playing: { | |
on: { | |
'': { | |
cond: (context) => context.plays >= 3, |
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
const donutMachine = Machine({ | |
id: 'donut', | |
initial: 'ingredients', | |
states: { | |
ingredients: { | |
on: { | |
NEXT: 'directions' | |
} | |
}, | |
directions: { |
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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - 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
Machine({ | |
id: 'screen', | |
initial: 'inactive', | |
states: { | |
inactive: { | |
on: { | |
TURN_ON: 'active' | |
} | |
}, | |
active: { |
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
const buttonFactory = id => { | |
const toggleName = `TOGGLE${id}` | |
return { | |
id: `button${id}`, | |
initial: 'off', | |
states: { | |
off: { | |
on: { | |
[toggleName]: 'on' | |
} |
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
const initial = {}; | |
const fetchMachine = Machine({ | |
id: 'panel', | |
initial: 'waiting', | |
context: initial, | |
states: { | |
waiting: { | |
// always reset to initial context | |
entry: assign(() => initial), | |
on: { |
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
// No TypeScript | |
function add(a, b) { | |
return a + b; | |
} | |
// Type function arguments | |
// vvvvvv vvvvvv | |
function add(a: number, b: number) { | |
return a + b; | |
} |
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
const ticker = ctx => cb => { | |
const interval = setInterval(() => { | |
cb("TICK"); | |
}, ctx.interval * 1000); | |
return () => clearInterval(interval); | |
}; | |
const timerExpired = (ctx) => ctx.elapsed >= ctx.duration; |
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
Machine({ | |
id: 'questionnaire', | |
initial: 'symptoms', | |
states: { | |
symptoms: { | |
on: { | |
NEXT: 'fluTest' | |
} | |
}, | |
fluTest: { |
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
Machine({ | |
id: 'Dog API', | |
initial: 'idle', | |
context: { | |
dog: null | |
}, | |
states: { | |
idle: { | |
on: { | |
FETCH: 'loading' |