@ua/react-native-airship
Version:
Airship plugin for React Native apps.
70 lines (63 loc) • 2 kB
JavaScript
;
/**
* Airship feature flag manager.
*/
export class AirshipFeatureFlagManager {
/**
* Feature flag cache.
*/
constructor(module) {
this.module = module;
this.resultCache = new AirshipFeatureFlagResultCache(module);
}
/**
* Retrieve a given flag's status and associated data by its name.
* @param {string} flagName The flag name
* @param {boolean} useResultCache If the response should use result cache or not.
* @return {Promise<FeatureFlag>} A promise resolving to the feature flag requested.
* @throws {Error} when failed to fetch
*/
flag(flagName, useResultCache = true) {
return this.module.featureFlagManagerFlag(flagName, useResultCache);
}
/**
* Tracks a feature flag interaction event.
* @param {FeatureFlag} flag The flag
* @return {Promise<Void>} A promise with an empty result.
* @throws {Error} when failed to fetch
*/
trackInteraction(flag) {
return this.module.featureFlagManagerTrackInteraction(flag);
}
}
export class AirshipFeatureFlagResultCache {
constructor(module) {
this.module = module;
}
/**
* Retrieve a flag from the cache.
* @param {string} flagName The flag name
* @return {Promise<FeatureFlag>} A promise resolving to the feature flag.
*/
flag(flagName) {
return this.module.featureFlagManagerResultCacheGetFlag(flagName);
}
/**
* Caches a feature flag.
* @param {FeatureFlag} flag The flag
* @param {FeatureFlag} ttl Cache TTL in milliseconds.
* @return {Promise<Void>} A promise with an empty result.
*/
cache(flag, ttl) {
return this.module.featureFlagManagerResultCacheSetFlag(flag, ttl);
}
/**
* Clears the cache for a given flag.
* @param {FeatureFlag} flagName The flag name
* @return {Promise<Void>} A promise with an empty result.
*/
removeCachedFlag(flagName) {
return this.module.featureFlagManagerResultCacheRemoveFlag(flagName);
}
}
//# sourceMappingURL=AirshipFeatureFlagManager.js.map