Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Available variables:
- // - Machine
- // - interpret
- // - assign
- // - send
- // - sendParent
- // - spawn
- // - raise
- // - actions
- // - XState (all XState exports)
- const compilationMachine = Machine({
- id: 'compilation',
- initial: 'idle',
- context: {
- errors: []
- },
- states: {
- idle: {
- on: {
- RUN: 'running'
- }
- },
- running: {
- on: {
- DONE: 'done'
- }
- },
- done: {
- type: 'final'
- }
- }
- });
- const compilerMachine = Machine({
- id: 'compiler',
- initial: "initializing",
- context: {
- compilations: []
- },
- states: {
- initializing: {
- entry: assign({
- compilations: (ctx, e) => {
- return ctx.compilations.map(c => ({
- ...c,
- ref: spawn(compilationMachine.withContext(c))
- }));
- },
- }),
- },
- running: {},
- completed: {}
- },
- on: {
- "MARK.running": {
- actions: ctx => {
- ctx.compilations.forEach(c => c.ref.send("RUN"));
- }
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement