Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exit action is not triggered on child machine #1109

Closed
piojablonski opened this issue Apr 2, 2020 · 6 comments · Fixed by #1566
Closed

exit action is not triggered on child machine #1109

piojablonski opened this issue Apr 2, 2020 · 6 comments · Fixed by #1566
Assignees
Labels

Comments

@piojablonski
Copy link

piojablonski commented Apr 2, 2020

Description
Child machine runs using invoke on parent machine. Child machine has exit action defined.

Expected Result
I expect child machine exit action to trigger after it reaches it final state

Actual Result
Exit action on child machine is not fired

Reproduction

const childMachine = Machine({
  entry: () => { console.log('entry') },
  exit: () => { console.log('exit') },
  initial: 'a',
  states: {
    a: {
      type: 'final'
    }
  }
})

const parentMachine = Machine({
  initial: 'active',
  states: {
    active: {
      invoke: {
        src: childMachine,
        onDone: 'finished'
      }
    },
    finished: {
      type: 'final'
    }
  }
})

https://xstate.js.org/viz/?gist=5ebf91269382bbd3e0bc66c62643a2fa

@Andarist
Copy link
Member

Andarist commented Apr 2, 2020

I can confirm that this should be fired as per exitInterpreter procedure

@piojablonski
Copy link
Author

piojablonski commented Apr 3, 2020

I tried to do a workaround by using an "a" state exit hook, unfortunately id doesn't work either.

const childMachine = Machine({
  entry: () => { console.log('entry') },
  
  // this is not trigerred
  exit: () => { console.log('exit') },

  initial: 'a',
  states: {
    a: {
      type: 'final',
      
      // this is not triggered either
      exit: () => { console.log('"a" state exit')}

    }
  }
})

@Andarist Andarist self-assigned this May 8, 2020
@Andarist
Copy link
Member

Im looking into fixing this and while this is on fact defined behavior in SCXML Im wondering - what is your exact real life use case for this? Im trying to think through what unexpected things this change might cause for people.

@davidkpiano
Copy link
Member

Related to #1111?

@Andarist
Copy link
Member

Not quite - when looking at #1111 resolution. This is about what we were discussing today - aligning with SCXML spec by calling onExit handlers for canceled/finalized machines. I hope to get this done this week.

@chromakode
Copy link

Just bumped into this too. Here's my example use case: a child machine that acquires microphone access using getUserMedia. I want to trigger an action when the machine is destroyed so I can release the microphone access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants