Skip to content

Instantly share code, notes, and snippets.

const config = {
key: 'virtual-funding-as-hub',
initial: 'createChannels',
states: {
createChannels: {
entry: 'assignChannels',
type: 'parallel',
states: {
createLeftGuarantorChannel: {
invoke: { src: 'createNullChannel', data: 'guarantorChannelArgs' },
const fileMachine = Machine({
id: 'file',
type: 'parallel',
states: {
upload: {
initial: 'idle',
states: {
idle: {
on: {
INIT_UPLOAD: 'pending',
function fetchData() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(Math.floor(Math.random() * 100));
}, 2000)
})
}
const fetchMachine = Machine({
id: 'fetch',
@andrewgordstewart
andrewgordstewart / machine.js
Last active January 22, 2020 00:36
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
context: {
retries: 0,
},
states: {
idle: {
on: {
FETCH: 'loading',
@andrewgordstewart
andrewgordstewart / machine.js
Last active January 23, 2020 00:51
Generated by XState Viz: https://xstate.js.org/viz
const config = {
initial: 'start',
on: { FUNDED: 'done' },
states: {
start: { entry: 'spawnDepositWatcher', on: { '': 'idle' } },
idle: { on: { SAFE_TO_DEPOSIT: 'submit' } },
submit: { invoke: { src: 'submitDepositTransaction', onDone: 'done', onError: 'failure' } },
done: { type: 'final' },
failure: {
entry: function() {
const config = {
type: 'parallel',
states: {
watcher: {
initial: 'watching',
states: { watching: { invoke: { src: 'subscribeDepositEvent' } }, done: { type: 'final' } },
on: { FUNDED: '.done' },
},
depositor: {
initial: 'idle',
const config = {
key: 'direct-funding',
initial: 'checkCurrentLevel',
states: {
checkCurrentLevel: { invoke: { src: 'checkCurrentLevel', onDone: 'updatePrefundOutcome' } },
updatePrefundOutcome: {
initial: 'getPrefundOutcome',
states: {
getPrefundOutcome: { invoke: { src: 'getPrefundOutcome', onDone: 'supportState' } },
supportState: {
const config = {
key: 'direct-funding',
initial: 'checkCurrentLevel',
states: {
checkCurrentLevel: { invoke: { src: 'checkCurrentLevel', onDone: 'updatePrefundOutcome' } },
updatePrefundOutcome: {
initial: 'getPrefundOutcome',
states: {
getPrefundOutcome: { invoke: { src: 'getPrefundOutcome', onDone: 'supportState' } },
supportState: {
const config = {
key: 'direct-funding',
initial: 'checkCurrentLevel',
states: {
checkCurrentLevel: { invoke: { src: 'checkCurrentLevel', onDone: 'updatePrefundOutcome' } },
updatePrefundOutcome: {
initial: 'getPrefundOutcome',
states: {
getPrefundOutcome: { invoke: { src: 'getPrefundOutcome', onDone: 'supportState' } },
supportState: {
const config = {
key: 'direct-funding',
initial: 'checkCurrentLevel',
states: {
checkCurrentLevel: { invoke: { src: 'checkCurrentLevel', onDone: 'updatePrefundOutcome' } },
updatePrefundOutcome: {
initial: 'getPrefundOutcome',
states: {
getPrefundOutcome: { invoke: { src: 'getPrefundOutcome', onDone: 'supportState' } },
supportState: {