Emitting an event is anti patter in ember js

Hi,

I am emitting an event from one controller to different component. Is it bad practice to use to emit events to/from different componente/controllers. Reply would be highly appreciated.

Thanks in advance!

I don’t fully understand what you mean, can you give an example?

In general, for a controller to effect the components that are rendered under it, the controller would change the data that is flowing down to them (“data down”) and if the components want to effect the controller they would use actions (“actions up”).

I have two different routes altogether. And wanna communication between their components or controllers. I know how data passed or actions bubble between children and parent components or between controller and its components. I’m doing this using Ember evented by triggering an event. Is it good idea in this case to use ember events or there is a better approach?

I would suggest using a Service (because it’s easy to inject into any controllers or components that want to talk to it), and just having your own functions on the service for communication.

Using the Ember evented stuff doesn’t really buy you much. It’s only there because the internals use it. For your own application-specific communications, your code will be easier to read and debug if you just do the simpler thing and have your own functions on the service to coordinate.

2 Likes