-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclientWithContext.js
More file actions
34 lines (27 loc) · 885 Bytes
/
clientWithContext.js
File metadata and controls
34 lines (27 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const handleUndefinedFeature = require('./lib/handleUndefinedFeature');
class ClientWithContext {
constructor({context, client, config}) {
this.context = context;
this.client = client;
this.config = config;
}
getFeature(key, defaultValue) {
// get the full feature
const featureState = this.client.getFeatureState(key);
if (!featureState) {
return handleUndefinedFeature(key, defaultValue);
}
if (featureState.value === false) {
return false;
}
// evaluate the strategy and return the updated feature (based on the strategy and context)
return featureState.strategy.calculate(this.context) // either true/false;
}
addGoogleAnalyticsCollector(params) {
return this.client.addGoogleAnalyticsCollector(params);
}
logEvent(params) {
this.client.logEvent(params);
}
}
module.exports = ClientWithContext;