-
Notifications
You must be signed in to change notification settings - Fork 34
/
ExperimentsProvider.tsx
50 lines (41 loc) · 1.5 KB
/
ExperimentsProvider.tsx
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { GOOGLE_PLAY_STORE, IS_IOS } from '~/config/Config';
import sp from '~/services/serviceProvider';
/**
* Return whether a feature has a given variation state.
* @param { string } featureKey - growthbook feature key.
* @param { string|number|boolean } variation - variation to check, e.g. 'on' or 'off'.
* @returns { boolean } - true if params reflect current variation.
*/
export function hasVariation(
featureKey: FeatureID | FeatureID[],
variation: boolean | string = true,
) {
return Array.isArray(featureKey)
? featureKey.every(
key => sp.resolve('analytics').getFeatureFlag(key) === variation,
)
: sp.resolve('analytics').getFeatureFlag(featureKey) === variation;
}
/**
* Update growthbook's attributes and features
*/
export function updateFeatureFlags() {
sp.resolve('analytics').initFeatureFlags();
}
export function useIsFeatureOn(feature: FeatureID) {
return sp.resolve('analytics').getFeatureFlag(feature);
}
export function useFeature(feature: FeatureID) {
return sp.resolve('analytics').getFeatureFlag(feature);
}
export const useIsIOSFeatureOn = (feature: FeatureID) =>
useIsFeatureOn(feature) && IS_IOS;
export const useIsAndroidFeatureOn = (feature: FeatureID) =>
useIsFeatureOn(feature) && !IS_IOS;
export const useIsGoogleFeatureOn = (feature: FeatureID) =>
useIsFeatureOn(feature) && GOOGLE_PLAY_STORE;
export const featureList = [
'epic-358-chat-mob',
'mobile-create-group-chat-new',
] as const;
export type FeatureID = typeof featureList[number];