Lets say I have a standalone addon with a playback component:
{{my-record play="recordPlay" stop="recordStop"}}
/app/components/my-record.js
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
play: function() {
this.sendAction('play');
},
stop: function() {
this.sendAction('stop');
}
}
});
I want the addon to work independently with backend and handle all actions internally.
How do I handle these two actions recordPlay
and recordStop
from within the addon itself so that I don't need to touch controller/routes of the consuming application?
I have tried:
creating application controller within the addon eg. `/app/controllers/application.js - this is never called
creating application route within the addon eg. `/app/routes/application.js - this is called unless consuming application has it's own ApplicationRoute which overrides the addon's route
Can I use initializers somehow from within the addon to inject these two actions to ApplicationController?
EDIT: Dirty workaround using ApplicationRoute._actions
/app/initializers/record.js
export default {
name: 'record',
initialize: function(container, app) {
var applicationRoute = container.lookup('route:application');
applicationRoute._actions.recordPlay = function(id) {
console.log('CALLED recordPlay', id);
};
applicationRoute._actions.recordStop = function(id) {
console.log('CALLED recordStop', id);
};
}
};