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 booleanMachine = Machine({ | |
id: "bool", | |
initial: "false", | |
states: { | |
false: { | |
on: { | |
TOGGLE: "true", | |
}, | |
}, | |
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
const MAX_ALLOWABLE_ATTEMPTS = 3 | |
const userLoginMachine = Machine({ | |
id: "userLogin", | |
initial: "loginScreen", | |
context: { | |
authError: "", | |
attemptCount: 0, | |
}, | |
states: { |
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 MIN_ATTEMPTS = 5 | |
const attemptsDelayedRefetchForeverMachine = Machine({ | |
id: "attemptsDelayedRefetchForever", | |
initial: "fetching", | |
context: { | |
numberOfAttempts: 0, | |
}, | |
states: { | |
fetching: { |
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 delayedTransientRefetchForeverMachine = Machine({ | |
id: "delayedTransientRefetchForever", | |
initial: "fetching", | |
states: { | |
fetching: { | |
invoke: { | |
id: "fetchHandler", | |
src: (ctx, e) => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
reject() |
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 refetchForeverMachine = Machine({ | |
id: "refetchForever", | |
initial: "fetching", | |
states: { | |
fetching: { | |
invoke: { | |
id: "fetchHandler", | |
src: (ctx, e) => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
// if (Math.random() < 0.5) { |
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 naiveRefetchForeverMachine = Machine({ | |
id: "naiveRefetchForever", | |
initial: "fetching", | |
states: { | |
fetching: { | |
invoke: { | |
id: "fetchHandler", | |
src: (ctx, e) => new Promise((resolve, reject) => { | |
setTimeout(() => { | |
// if (Math.random() < 0.5) { |
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 fetchMachine = Machine({ | |
id: "fetch", | |
initial: "fetching", | |
states: { | |
// idle: { | |
// on: { | |
// FETCH: "fetching", | |
// }, | |
// }, | |
fetching: { |
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 userMachine = Machine({ | |
id: "user", | |
initial: "loading", | |
states: { | |
loading: { | |
invoke: { | |
id: "loadingHandler", | |
src: (ctx, _) => (callback, _) => { | |
setTimeout(() => { | |
callback("success") |
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 delayedSwitch = Machine({ | |
id: "delayedSwitch", | |
initial: "disabled", | |
states: { | |
switchToDisabled: { | |
after: { | |
1e3: "disabled", | |
}, | |
}, | |
disabled: { |
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 switchMachine = Machine({ | |
id: 'switch', | |
initial: 'disabled', | |
states: { | |
disabled: { | |
on: { | |
TOGGLE: "enabled", | |
}, | |
}, | |
enabled: { |