Skip to content

A smart feature toggle library with housekeeping and dependency features

License

Notifications You must be signed in to change notification settings

dipunm/smart-feature-toggles

Repository files navigation

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)

About

A smart feature toggle library with housekeeping and dependency features

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published