Coder Social home page Coder Social logo

colinmathews / ember-feature-flags Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kategengler/ember-feature-flags

0.0 2.0 0.0 135 KB

Ember CLI addon for feature flags

License: MIT License

JavaScript 88.59% HTML 8.43% CSS 0.17% Handlebars 2.81%

ember-feature-flags's Introduction

ember-feature-flags Build Status Ember Observer Score

An ember-cli addon to provide feature flags.

Installation

ember install:addon ember-feature-flags

Usage

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
});

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.js
module.exports = function(environment) {
  var ENV = {
    featureFlags: {
      'show-spinners': true,
      'download-cats': false
    }
  };

  if (environment === 'production') {
    ENV.featureFlags['download-cats'] = true;
  }

  return ENV;
};

config.featureFlagsService

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;
};

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

withFeature

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');
  });
});

withoutFeature

Turns off a feature for the test in which it is called. To use, import into your test-helper.js: import 'ember-feature-flags/tests/helpers/without-feature' and add to your test .jshintrc, it will now be available in all of your tests.

Example:

import 'ember-feature-flags/tests/helpers/without-feature';

test( "links do NOT go to the new homepage", function () {
  withoutFeature( 'new-homepage' );

  visit('/');
  click('a.home');
  andThen(function(){
    notEqual(currentRoute(), 'new.homepage', 'Should not be on the new homepage');
  });
});

Development

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

ember-feature-flags's People

Contributors

colinmathews avatar dandehavilland avatar ember-tomster avatar kategengler avatar mixonic avatar pgengler avatar simonexmachina avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.