Last active
October 8, 2020 06:16
-
-
Save pyoner/ecd225b098f8b2a5d8cfa481f1c8d249 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 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