Skip to content

Instantly share code, notes, and snippets.

@tamebadger
Last active October 31, 2019 09:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamebadger/1e9b740f1605b7753dddb1d3ed4ebcf9 to your computer and use it in GitHub Desktop.
Save tamebadger/1e9b740f1605b7753dddb1d3ed4ebcf9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const parentMachine = Machine({
id: 'your_id_here',
initial: 'pending',
states: {
pending: {
on: { CHANGE_EVENT: 'process' }
},
process: {
type: 'parallel',
states: {
fetchMachine1: {
initial: 'initialize',
states: {
initialize: {
on: {
'FETCH.REQUEST': {
target: 'pending',
}
}
},
pending: {
invoke: {
src: 'fetch',
onDone: {
target: 'success',
actions: ['updateResponse']
},
onError: {
target: 'failure',
actions: ['updateError']
}
},
},
success: {
entry: ['fetchSuccess'],
on: {
'FETCH.REQUEST': 'pending'
},
type: 'final' // 'success' is a final state node for 'fetchMachine1'
},
failure: {
entry: ['fetchFailure'],
on: {
'FETCH.REQUEST': 'pending'
}
}
}
},
fetchMachine2: {
initial: 'initialize',
states: {
initialize: {
on: {
'FETCH.REQUEST': {
target: 'pending',
}
}
},
pending: {
invoke: {
src: 'fetch',
onDone: {
target: 'success',
actions: ['updateResponse']
},
onError: {
target: 'failure',
actions: ['updateError']
}
},
},
success: {
entry: ['fetchSuccess'],
on: {
'FETCH.REQUEST': 'pending'
},
type: 'final' // 'success' is a final state node for 'fetchMachine1'
},
failure: {
entry: ['fetchFailure'],
on: {
'FETCH.REQUEST': 'pending'
}
}
}
}
},
onDone: 'pending'
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment