Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {
- Machine,
- interpret,
- send
- } = require('xstate');
- const childMachine = Machine({
- id: 'child',
- initial: 'second',
- states: {
- second: {
- on: {
- SECOND: {
- target: 'third',
- actions: [(context, event, actionMeta) => {
- console.log('Child Machine is in the 2nd state -> ', context)
- }, send('THIRD')]
- }
- }
- },
- third: {
- on: {
- THIRD: {
- actions: [(context, event, actionMeta) => {
- console.log('Child Machine is in the 3rd state -> ', context)
- }]
- }
- }
- }
- }
- });
- const parentMachine = Machine({
- id: 'parent',
- initial: 'first',
- states: {
- first: {
- invoke: {
- id: 'child',
- src: childMachine
- },
- on: {
- FIRST: {
- actions: [(context, event, actionMeta) => {
- console.log('Parent Machine is in the 1st state -> ', context)
- }, send('SECOND', {
- to: 'child'
- })]
- }
- }
- }
- }
- });
- const parentMachineService = interpret(parentMachine).start()
- parentMachineService.send('FIRST')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement