Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between sendAction and send?

Tags:

I have defined two custom objects, whereby the first one is extending Ember.TextField and the second one Ember.Select. When the appropriate action is trigger in Ember.TextField I do some processing and if a requirement is satisfied then I propagate the action to the underlying controller using @sendAction("actionName").

However, when I try to do the same using Ember.Select I get the following Error:

Uncaught TypeError: Object [object Object] has no method 'sendAction'  

and have to use @get("controller").send("actionName") instead. My mentor reckons that this inconsistency leads to spaghetti code and I do agree with him. Why can't I call @sendAction from Ember.Select, which is a preferred way I've come to understand, in Ember?

What is the main difference between the two?

like image 737
Dragan Avatar asked Jan 27 '14 06:01

Dragan


People also ask

What is sendAction in Ember?

You can send parameters with an action by using sendAction() method which provides additional context to the route or controller to handle an action and has string 'action' as the first argument.

What is the prime task performed by controllers in Ember JS?

What are the prime tasks that are performed by controllers in Ember. js? Decorating the model which is returned by the route is a very essential task that needs to be performed in Ember.


1 Answers

sendAction should be used when inside a component. It allows you to breach the confines of a component, if that action is defined when hooking up the component. This helps keep maintain the isolation guaranteed by components, but still allows the component to send messages if you want to listen to it. https://guides.emberjs.com/v2.4.0/components/triggering-changes-with-actions/

{{my-component someInternalAction=someExternalAction}} 

send should be used everywhere else.

Ember.Select and Ember.TextField are both components, hence you need to use sendAction

like image 129
Kingpin2k Avatar answered Sep 18 '22 12:09

Kingpin2k