An ember-cli addon to provide feature flags.
ember.js
>= 3.1
Note to users of Referencing the features service must be done using get
as it is a proxy.
Installation
ember install ember-feature-flags
Usage
This addon provides a service named features
available for injection into your routes, controllers, components, etc.
For example you may check if a feature is enabled:
;;;
Features are also available as properties of features
. They are camelized.
;;;;
Check whether a feature is enabled in a template (be sure to inject the features service into the template's backing JavaScript):
// templates/components/homepage-link.hbs{{#if features.newHomepage}} {{link-to "new.homepage"}}{{else}} {{link-to "old.homepage"}}{{/if}}
NOTE: features
service must be injected into the respective component:
// components/homepage-link.js;
Alternatively you can use a template helper named feature-flag
:
// templates/components/homepage-link.hbs{{#if (feature-flag 'newHomepage')}} {{link-to "new.homepage"}}{{else}} {{link-to "old.homepage"}}{{/if}}
Features can be toggled at runtime, and are bound:
this;this;
Features can be set in bulk:
this;
You may want to set the flags based on the result of a fetch:
// routes/application.jsfeatures: { return ;}
NOTE: setup
methods reset previously setup flags and their state.
You can get list of known feature flags via flags
computed property:
this; this // ['newBillingPlans', 'newHomepage']
Configuration
config.featureFlags
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.jsmodule { var ENV = featureFlags: 'show-spinners': true 'download-cats': false ; if environment === 'production' ENVfeatureFlags'download-cats' = true; return ENV;};
ENV.LOG_FEATURE_FLAG_MISS
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.
Test Helpers
enableFeature
Turns on a feature for the test in which it is called.
Requires ember-cli-qunit >= 4.1.0 and the newer style of tests that use setupTest
, setupRenderingTest
, setupApplicationTest
.
Example:
; module'Acceptance | Awesome page' { ; ;};
withFeature
"Old"-style acceptance tests can utilize withFeature
test helper to turn on a feature for the test.
To use, import into your test-helper.js: import 'ember-feature-flags/test-support/helpers/with-feature'
and add to your
test .jshintrc
, it will now be available in all of your tests.
Example:
; ;
Integration Tests
If you use this.features.isEnabled()
in components under integration test, you will need to inject a stub service in your tests. Using ember-qunit 0.4.16 or later, here's how to do this:
let featuresService = Service; ;
Note: for Ember before 2.3.0, you'll need to use ember-getowner-polyfill.
Development
Installation
git clone
this repository- cd ember-feature-flags`
yarn install
Running
ember serve
- Visit your app at http://localhost:4200.
Running Tests
ember try:each
(Test against multiple ember versions)ember test
ember test --server
Deploying
- See RELEASE.md