#Emit on action, WITH params

1 messages · Page 1 of 1 (latest)

pine talon
#

I have a state called "Attract mode" which has an "entry" event defined like this:

entry: {
        type: "instructDisplays",
        params: {
          layout: "attract",
        },
      },

For the code that implements the action, I chose "emit", and of course I get something like this:

export default emit({
  type: 'instructDisplays'
})

Which is all fine, but I don't seem to have any access to the params I set for the action.

If I define the action a bit differently, it seems I can access the params, but then the call to emit seems to do nothing!

  actions: {
    instructDisplays: (_, params: { layout: string }) => {
      console.log("should emit now...", params);
      emit({
        type: "instructDisplays",
        layout: params.layout
      });
    },
    // instructDisplays: emit({ type: "instructDisplays" }),
  },

When I subscribe to events as before, I see the console.logs "should emit now", etc., but not "instructDisplays event" as below:

root.on("instructDisplays", (event) => {
    console.log("instructDisplays event:", event);
})

What am I missing about actions and their params, especially when relating to emit ?

mint raptor
#

You are calling emit imperatively - this won't do anything

#

Over here:

    instructDisplays: (_, params: { layout: string }) => {
      console.log("should emit now...", params);
      emit({
        type: "instructDisplays",
        layout: params.layout
      });
    },
pine talon
#

That does make sense, but then how do I get the action "instructDisplays" to emit an event with "whatever params were passed"?

mint raptor
#
instructDisplays: emit((_, params: { layout: string }) => {
  // ...
  return { type: 'instructDisplays', layout: params.layout }
})