Skip to content

Instantly share code, notes, and snippets.

@gretzky
Last active February 16, 2021 16:42
Show Gist options
  • Save gretzky/858a4116c07c129e8214f5aac8d2f331 to your computer and use it in GitHub Desktop.
Save gretzky/858a4116c07c129e8214f5aac8d2f331 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
id: 'createDialFinal',
initial: 'init',
context: {
newDial: null,
error: false,
errorMsg: '',
syncRetries: 0,
connectRetries: 0,
createRetries: 0
},
states: {
init: {
on: {
SCAN_QR_CODE: "scanQRCode"
}
},
scanQRCode: {
on: {
NEXT: "syncing",
EXIT: "init"
}
},
syncing: {
on: {
RESOLVE: "wifi",
REJECT: "syncFailure"
}
},
syncFailure: {
on: {
RETRY: {
target: "syncing",
actions: assign({
syncRetries: (ctx, event) => ctx.syncRetries + 1
})
}
}
},
wifi: {
on: {
NEXT: "connect",
EXIT: "init"
}
},
connect: {
on: {
RESOLVE: "dialType",
REJECT: "connectFailure"
}
},
connectFailure: {
on: {
RETRY: {
target: "connect",
actions: assign({
connectRetries: (ctx, event) => ctx.connectRetries + 1
})
}
}
},
dialType: {
on: {
NEXT: "dialName",
EXIT: "init"
}
},
dialName: {
on: {
NEXT: "dialArea",
BACK: "dialType"
}
},
dialArea: {
on: {
NEXT: "creating",
BACK: "dialName"
}
},
creating: {
on: {
RESOLVE: "createSuccess",
REJECT: "createFailure"
}
},
createSuccess: {
on: {
HOME: "init",
ADD_ANOTHER: "scanQRCode"
}
},
createFailure: {
on: {
RETRY: {
target: "creating",
actions: assign({
createRetries: (ctx, event) => ctx.createRetries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment