1
votes

In ember, we have the action helper;

{{action "actionName" arg1 arg2}}  

But, when I want to send actions to a parent component, I still have to explicitly write an action on the child that calls sendAction. Even if I'm ONLY bubbling an action. I'd like the avoid this with a send-action helper;

{{send-action "actionKey" arg1 arg2}}  

Does anyone know how I'd implement this helper?

1

1 Answers

4
votes

You should use closure actions instead, as shown in Triggering Changes with Actions.

So if you have an action in a parent component named actionKey, you do the following.

Pass it to the child component as a closure action:

{{my-component myName=(action 'actionKey')}}

And then in the template of your child component:

<button {{action myName arg1 arg2}}>click me</button>

I used myName for illustrative purposes, it can be whatever you want as long as it matches the name you use inside the component.

I have reproduced the above in a Twiddle: https://ember-twiddle.com/fd56b0b9d017968fc334b3f109760806.