0.0.4 • Published 2 months ago
flagr-feature-typescript v0.0.4
flagr-feature-typescript
Prerequisites
To use this package, you will need to have Flagr installed and accessible
Usage
Configuration
const feature = createFeature({ flagrUrl: 'http://localhost:18000' });
Evaluation
const evaluation = feature.evaluate('flag', {
on: (attachment) => true, // do stuff when feature is on,
otherwise: (attachment) => false, // do stuff when any other variant isn't matched
});
console.log(evaluation); // return from evaluate
Conditional
const match = feature.match('flag'); // true if evaluated variant is 'on'
const matchOff = feature.match('flag2', 'off'); // true evaluated variant is 'off'
Synchronous usage
In the event that you can't use promises (such as within React components), you can directly use the evaluator.
// Invoked in a global context
const evaluator = createEvaluator(config);
const { cachedMatch, cachedEvaluation } = await evaluator.batchEvaluation({
id: 'user_123',
context: {}
input: {
tags: ['local'],
},
});
// ...
// Invoked in a synchronous context
const isOn = cachedMatch('flag1');
NB: All flags are prefetched via the evaluator. This requires you to supply the superset flags required via either keys
or tags
Context
Context can be sent during evaluation
feature.setContext({
env: 'production',
user: { id: 1, username: 'user' },
});
0.0.5-o84637b.0
2 months ago
0.0.5-5179f2e.0
2 months ago
0.0.5-e424908.0
2 months ago
0.0.5-63d78a8.0
2 months ago
0.0.5-9b0daa5.0
2 months ago
0.0.4
2 months ago
0.0.5-85a256f.0
2 months ago
0.0.2-8488dc1.0
2 years ago
0.0.2-bf79484.0
2 years ago
0.0.2-51b57d8.0
2 years ago
0.0.2-d421f26.0
2 years ago
0.0.2-8ef6efb.0
2 years ago
0.0.2-c11450b.0
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.2-3869072.0
2 years ago
0.0.2-c39cdf1.0
2 years ago
0.0.2-o356739.0
2 years ago
0.0.1
3 years ago