Sending events inside action #1835
-
In my situation, I have entry actions that draw some graphical objects for each state: it's something like:
But I need to capture events of this viewcontrollers tp translate into events for my machine. I should do something like:
But, of course, I cannot use send action creator in this way. How can I send an event in the most efficient way in my situation? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Sounds like you want this Invoke the 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
}
} |
Beta Was this translation helpful? Give feedback.
-
@davidkpiano Yes, invoking callbacks is something I usually forget, but it's a brilliant solution for my situation.
|
Beta Was this translation helpful? Give feedback.
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: