Skip to content

Instantly share code, notes, and snippets.

@pyoner
Last active October 8, 2020 06:16
Show Gist options
  • Save pyoner/ecd225b098f8b2a5d8cfa481f1c8d249 to your computer and use it in GitHub Desktop.
Save pyoner/ecd225b098f8b2a5d8cfa481f1c8d249 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 sessionStart = Machine({
id: 'sessionStart',
initial: 'run',
states: {
run: {
entry: ['log'],
type: 'final'
}
}
}, {
actions: {
log(context, event){
console.log('log', context, event)
}
}
});
const sessionManager = Machine({
id: 'sessionManager',
type: 'parallel',
initial: 'idle',
context: {
sessions: []
},
states: {
idle: {
on: {
START: {
target: 'start',
actions: ['addSession']
}
}
},
start: {
invoke: {
id: 'sessionStart',
onDone: 'save',
onError: 'error'
}
},
save: {
invoke: {
id: 'sessionSave',
onDone: 'idle',
onError: 'error'
}
},
error: {
invoke: {
id: 'sessionError',
onDone: 'idle'
}
}
}
}, {
actions: {
addSession(context, event) {
console.log('addSession', context, event)
context.sessions.push(event.session)
}
},
services: {
sessionStart
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment