So, I have a notification-container controller, which implements a ‘pushNotification’ action:
app/contolllers/notification-container.js:
export default Ember.Controller.extend({
actions: {
pushNotification: function (type, title, message) {
// send a notification....
}
}
});
If I would like to call that method from another controller, I have to tell the controller that it needs the other controller:
needs: ['notification-container'],
and then in order to trigger the notification:
this.get('controllers.notification-container').send('pushNotification', 'success', 'title', 'test');
That not only doesn’t look very nice, but I have to tell every controller that needs to send notifications that it needs to depend on the notification-container controller. So, I was hoping to find a smarter way to deal with this. Unfortunately it looks like I can’t use mixins easily if I need to call another controller. So, the only thing that seems to work is to extend all the different ember controller types with custom ones, that implement a function to send out notifications. Still a lot of duplicate code…
I found there is an ControllerMixin, however besides its name, it does not seem to be made for being a mixing for your controllers.
Is there any good way to deal with that? In the end I would just like to do something like “Notification.warn(‘title’, ‘text’);” which then would make the appropriate calls to the controller, but I can’t figure out how to make that available globally.