dimanche 21 décembre 2014

Best way of passing arguments to ember addon source code

TL;DR


Is it possible to pass the options from the addon's index.js file to the addon's Ember application?


More detail


Ember CLI addon's allow you to pass options to an addon by setting options in your Brocfile.js.



var EmberApp = require('ember-cli/lib/broccoli/ember-app');

var app = new EmberApp({
myAddon: {
enabled: false // TODO - Change when CLoudfront is implemented
},
});


You can then access these options in the addon's index.js file like so:



module.exports = {
name: 'my-addon',

included: function(app) {
var options = app.options.myAddon;
}
}


However, what if I want to use these options in an Ember component or view or other class in the addon? For example, a component:



import Em from 'ember';

export default Em.Component.extend({

doSomething: function() {
if (this.get('options.enabled')) {
// Then do something
}
},

});


Is it possible to pass the options from the addon's index.js file to the addon's Ember application?


Please note, I'm aware you could just pass the argument to the component in the template but that's not the point of this question. Thanks.





Aucun commentaire:

Enregistrer un commentaire