1.0.1 • Published 6 years ago
smart-feature-toggles v1.0.1
Smart feature toggles
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
orinactive
. - 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)