Code Monkey home page Code Monkey logo

smart-feature-toggles's Introduction

Smart feature toggles

Build Status Client bundle size Client bundle size

Client sizes are based on a webpack bundle using the lite version of the library. (See Lite Client)

Contents

Installation

npm install smart-feature-toggles

Defining toggles

  • A feature toggle may only be active or inactive.
  • Feature toggles can be scoped (eg. to a http request, or to an application context).
  • A feature toggle should not change value between calls*.
  • A feature toggle cannot be given arguments when being queried. All dependencies should be defined and ready before a toggle is queried.
  • A feature toggle can be set up to alert developers when it is becoming old.

*Smart feature toggles will cache the calculated value based on this assumption, but the auto reset feature exists to satisfy more dynamic toggles.

Usage

Require smart-feature-toggles:

const FeatureToggles = require('smart-feature-toggles');

Set up alert handling: (see: Housekeeping)

FeatureToggles.onHealthAlert((name, alert) => console.log(name, alert));

Name and configure your features:

const features = [
  {
    name: 'my-feature',

    dependencies: ['request'],

    test: request => request.query.test_mode,

    health: () => {
      // If the toggle is getting old, return an alert
      if (new Date().getFullYear() > 2018) {
        return 'my-feature toggle is getting old!';
      }
    },
  },
];

Create your toggle client:

const toggles = FeatureToggles.create(features);

Define your dependencies: (see: Dependencies)

const request = { query: { test_mode: true } };
toggles.defineDependency('request', request);

Use your feature toggle:

if (toggles.get('my-feature')) { // true
    ...
}

// alternative syntax.
toggles.values['my-feature']; // true

// once evaluated, the toggle will
// always return it's original value
request.query.test_mode = false;
toggles.get('my-feature'); // true

Toggles can be set up to auto update (see: Auto Resets)

Features

Scoping:

Read about Scoping

Housekeeping:

Read about Housekeeping

Dependencies:

Read about Dependencies

Serialization:

Read about Serialization

Auto Resets:

Read about Auto Resets

Browser Compatibility:

Read about the Browser Compatibility

Lite Client:

Read about the Lite Client

API

see the API docs. (coming soon)

smart-feature-toggles's People

Contributors

dipunm avatar

Watchers

 avatar

smart-feature-toggles's Issues

Error when creating feature toggles

When calling FeatureToggles.create()

<project path>/node_modules/smart-feature-toggles/src/helpers/json.js:32
              ...json,
              ^^^

    SyntaxError: Unexpected token ...

Looks like node 8 doesn't like the spread operator within objects.

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.