Client sizes are based on a webpack bundle using the lite version of the library. (See Lite Client)
npm install smart-feature-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.
const FeatureToggles = require('smart-feature-toggles');
Set up alert handling: (see: Housekeeping)
FeatureToggles.onHealthAlert((name, alert) => console.log(name, alert));
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!';
}
},
},
];
const toggles = FeatureToggles.create(features);
Define your dependencies: (see: Dependencies)
const request = { query: { test_mode: true } };
toggles.defineDependency('request', request);
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)
Read about Scoping
Read about Housekeeping
Read about Dependencies
Read about Serialization
Read about Auto Resets
Read about the Browser Compatibility
Read about the Lite Client
see the API docs. (coming soon)