Files
outline/app/utils/FeatureFlags.ts
T
codegen-sh[bot] 879c568a2c Upgrade Prettier to v3.6.2 (#9500)
* Upgrade Prettier to v3.6.2 and eslint-plugin-prettier to v5.5.1

- Upgraded prettier from ^2.8.8 to ^3.6.2 (latest version)
- Upgraded eslint-plugin-prettier from ^4.2.1 to ^5.5.1 for compatibility
- Applied automatic formatting changes from new Prettier version
- All existing ESLint and Prettier configurations remain compatible

* Applied automatic fixes

* Trigger CI

---------

Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com>
Co-authored-by: Tom Moor <tom@getoutline.com>
2025-06-28 10:22:28 -04:00

49 lines
1.1 KiB
TypeScript

import { observable } from "mobx";
import Storage from "@shared/utils/Storage";
export enum Feature {
/** New collection permissions UI */
newCollectionSharing = "newCollectionSharing",
}
/** Default values for feature flags */
const FeatureDefaults: Record<Feature, boolean> = {
[Feature.newCollectionSharing]: true,
};
/**
* A simple feature flagging system that stores flags in browser storage.
*/
export class FeatureFlags {
public static isEnabled(flag: Feature) {
// init on first read
if (this.initalized === false) {
this.cache = new Set();
for (const key of Object.values(Feature)) {
const value = Storage.get(key);
if (value === true) {
this.cache.add(key);
}
}
this.initalized = true;
}
return this.cache.has(flag) ? true : (FeatureDefaults[flag] ?? false);
}
public static enable(flag: Feature) {
this.cache.add(flag);
Storage.set(flag, true);
}
public static disable(flag: Feature) {
this.cache.delete(flag);
Storage.set(flag, false);
}
@observable
private static cache: Set<Feature> = new Set();
private static initalized = false;
}