addons/isl/src/atoms/experimentalFeatureAtoms.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import {atom} from 'jotai';
b69ab319import {configBackedAtom, localStorageBackedAtom} from '../jotaiUtils';
b69ab3110
b69ab3111// This config is intended to be controlled remotely. So it's read-only.
b69ab3112const remoteExperimentalFeatures = configBackedAtom<boolean | null>(
b69ab3113 'isl.experimental-features',
b69ab3114 false,
b69ab3115 true /* read-only */,
b69ab3116);
b69ab3117
b69ab3118// 0: Respect remote config. 1: Enable experimental features. 2: Disable experimental features.
b69ab3119const localExperimentalFeatures = localStorageBackedAtom<number>(
b69ab3120 'isl.experimental-features-local-override',
b69ab3121 0,
b69ab3122);
b69ab3123
b69ab3124/**
b69ab3125 * List of all currently enabled experimental features, as UI labels.
b69ab3126 * UI setting to enable experimental features is only shown if this list is non-empty.
b69ab3127 */
b69ab3128export const currentExperimentalFeaturesList: Array<string> = [];
b69ab3129
b69ab3130/**
b69ab3131 * Whether experimental features are enabled.
b69ab3132 * Backed by a remote config by default. Can also be set locally.
b69ab3133 */
b69ab3134export const hasExperimentalFeatures = atom(
b69ab3135 get => {
b69ab3136 const localOverride = get(localExperimentalFeatures);
b69ab3137 if (localOverride === 1) {
b69ab3138 return true;
b69ab3139 } else if (localOverride === 2) {
b69ab3140 return false;
b69ab3141 } else {
b69ab3142 return get(remoteExperimentalFeatures) ?? false;
b69ab3143 }
b69ab3144 },
b69ab3145 (get, set, update) => {
b69ab3146 const newValue = typeof update === 'function' ? update(get(hasExperimentalFeatures)) : update;
b69ab3147 set(localExperimentalFeatures, newValue ? 1 : 2);
b69ab3148 },
b69ab3149);