Last active
January 18, 2020 23:47
-
-
Save jlengstorf/41c8f4af9cc46418a203b485f3baebbf to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 | |
// - XState (all XState exports) | |
const effectMachine = Machine({ | |
id: 'effect', | |
initial: 'idle', | |
context: { | |
name: undefined, | |
}, | |
states: { | |
idle: { | |
on: { | |
PLAY_EFFECT: 'playing' | |
} | |
}, | |
playing: {}, | |
} | |
}); | |
const dashboardMachine = Machine({ | |
id: 'dashboard', | |
initial: 'idle', | |
context: { | |
channel: undefined, | |
site: undefined, | |
functions: [], | |
}, | |
states: { | |
idle: { | |
on: { | |
LOGIN: 'login', | |
}, | |
}, | |
login: { | |
initial: 'twitch', | |
on: { | |
LOGIN_SUCCESS: 'configure', | |
}, | |
states: { | |
twitch: { | |
on: { | |
TWITCH_LOGIN_SUCCESS: { | |
actions: assign({ channel: 'def456' }), | |
target: 'netlify' | |
}, | |
} | |
}, | |
netlify: { | |
on: { | |
NETLIFY_LOGIN_SUCCESS: { | |
actions: send('LOGIN_SUCCESS'), | |
}, | |
}, | |
}, | |
} | |
}, | |
configure: { | |
initial: 'loading', | |
on: { | |
SITE_CONFIGURED: 'display', | |
}, | |
states: { | |
loading: { | |
on: { | |
'NETLIFY_SITES_LOADED': 'loaded', | |
}, | |
}, | |
loaded: { | |
on: { | |
SET_NETLIFY_SITE: { | |
actions: [ | |
assign({ site: 'abc123' }), | |
send('SITE_CONFIGURED') | |
] | |
} | |
} | |
}, | |
} | |
}, | |
display: { | |
initial: 'loading', | |
states: { | |
loading: { | |
on: { | |
FUNCTIONS_LOADED: { | |
actions: assign({ functions: [ | |
'command-blitzed', | |
]}), | |
target: 'loaded', | |
}, | |
}, | |
}, | |
loaded: { | |
type: 'final', | |
entry: assign({ | |
functions: (ctx, e) => ctx.functions.map(fn => ({ | |
name: fn, | |
ref: spawn(effectMachine.withContext({ name: fn })) | |
})) | |
}) | |
} | |
} | |
} | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment