Skip to content

Sending events inside action #1835

Answered by davidkpiano
smarko82 asked this question in Q&A
Discussion options

You must be logged in to vote

Sounds like you want this MenuViewController to be long-lived. Remember that actions are effects that are fire-and-forget; that is, they are not appropriate for things that need to be long-lived, and/or communicate back with the machine.

Invoke the MenuViewController() instead:

invoke: {
  id: 'homeView',
  src: () => (sendBack, receive) => {
    const homeViewControl = new MenuViewController();

    homeViewCtrl.onChangeFocus = () => sendBack('MENU_ITEM_CHANGED'));

    receive(event => {
      if (event.type === 'doSomething') {
        homeViewCtrl.doSomething();
      }
    });
    
    return () => { homeViewControl.destroy(); } // or similar
  }
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by smarko82
Comment options

You must be logged in to vote
1 reply
@Andarist
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants