An ember-cli addon to provide feature flags.
ember install ember-feature-flags
This addon injects a property features onto your routes, controllers and components.
For example you may check if a feature is enabled:
export default Ember.Controller.extend({
plans: function(){
if (this.features.isEnabled('new-billing-plans')){
// Return new plans
} else {
// Return old plans
}
}.property()
});Features are also available as properties of features. They are camelized.
export default Ember.Controller.extend({
plans: function(){
if (this.features.get('newBillingPlans')){
// Return new plans
} else {
// Return old plans
}
}.property('features.newBillingPlans')
});Check whether a feature is enabled in a template:
{{#if features.newHomepage}}
{{link-to "new.homepage"}}
{{else}}
{{link-to "old.homepage"}}
{{/if}}Features can be toggled at runtime, and are bound:
features.enable('newHomepage');
features.disable('newHomepage');Features can be set in bulk:
features.setup({
"new-billing-plans": true,
"new-homepage": false
});You can configure a set of initial feature flags in your app's config/environment.js file. This
is an easy way to change settings for a given environment. For example:
// config/environment.js
module.exports = function(environment) {
var ENV = {
featureFlags: {
'show-spinners': true,
'download-cats': false
}
};
if (environment === 'production') {
ENV.featureFlags['download-cats'] = true;
}
return ENV;
};The name of the features injection can be customized with the featureFlagsService config
option. For example:
// config/environment.js
module.exports = function(environment) {
var ENV = {
featureFlagsService: 'featuresService'
};
return ENV;
};Will log when a feature flag is queried and found to be off, useful to prevent cursing at the app, wondering why your feature is not working.
Turns on a feature for the test in which it is called.
To use, import into your test-helper.js: import 'ember-feature-flags/tests/helpers/with-feature' and add to your
test .jshintrc, it will now be available in all of your tests.
Example:
import 'ember-feature-flags/tests/helpers/with-feature';
test( "links go to the new homepage", function () {
withFeature( 'new-homepage' );
visit('/');
click('a.home');
andThen(function(){
equal(currentRoute(), 'new.homepage', 'Should be on the new homepage');
});
});git clonethis repositorynpm installbower install
ember server- Visit your app at http://localhost:4200.
ember testember test --server
ember build