Skip to content

Instantly share code, notes, and snippets.

View zaydek's full-sized avatar
🤠
Howdy!

Z 🏴‍☠️ zaydek

🤠
Howdy!
View GitHub Profile
const booleanMachine = Machine({
id: "bool",
initial: "false",
states: {
false: {
on: {
TOGGLE: "true",
},
},
true: {
@zaydek
zaydek / machine.js
Created September 19, 2020 20:41
Generated by XState Viz: https://xstate.js.org/viz
const MAX_ALLOWABLE_ATTEMPTS = 3
const userLoginMachine = Machine({
id: "userLogin",
initial: "loginScreen",
context: {
authError: "",
attemptCount: 0,
},
states: {
@zaydek
zaydek / machine.js
Created September 19, 2020 20:23
Generated by XState Viz: https://xstate.js.org/viz
const MIN_ATTEMPTS = 5
const attemptsDelayedRefetchForeverMachine = Machine({
id: "attemptsDelayedRefetchForever",
initial: "fetching",
context: {
numberOfAttempts: 0,
},
states: {
fetching: {
@zaydek
zaydek / machine.js
Created September 19, 2020 20:16
Generated by XState Viz: https://xstate.js.org/viz
const delayedTransientRefetchForeverMachine = Machine({
id: "delayedTransientRefetchForever",
initial: "fetching",
states: {
fetching: {
invoke: {
id: "fetchHandler",
src: (ctx, e) => new Promise((resolve, reject) => {
setTimeout(() => {
reject()
@zaydek
zaydek / machine.js
Created September 19, 2020 20:03
Generated by XState Viz: https://xstate.js.org/viz
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) {
@zaydek
zaydek / machine.js
Created September 19, 2020 19:58
Generated by XState Viz: https://xstate.js.org/viz
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) {
@zaydek
zaydek / machine.js
Last active September 19, 2020 19:41
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: "fetch",
initial: "fetching",
states: {
// idle: {
// on: {
// FETCH: "fetching",
// },
// },
fetching: {
@zaydek
zaydek / machine.js
Created September 19, 2020 19:32
Generated by XState Viz: https://xstate.js.org/viz
const userMachine = Machine({
id: "user",
initial: "loading",
states: {
loading: {
invoke: {
id: "loadingHandler",
src: (ctx, _) => (callback, _) => {
setTimeout(() => {
callback("success")
@zaydek
zaydek / machine.js
Last active September 19, 2020 19:22
Generated by XState Viz: https://xstate.js.org/viz
const delayedSwitch = Machine({
id: "delayedSwitch",
initial: "disabled",
states: {
switchToDisabled: {
after: {
1e3: "disabled",
},
},
disabled: {
@zaydek
zaydek / machine.js
Last active September 19, 2020 18:42
Generated by XState Viz: https://xstate.js.org/viz
const switchMachine = Machine({
id: 'switch',
initial: 'disabled',
states: {
disabled: {
on: {
TOGGLE: "enabled",
},
},
enabled: {