blob: ca9aa60eadd5ce144ce476f193210c80054fa531 [file] [log] [blame]
/**
* @license
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {Finalizable} from '../../types/types';
import {FlagsService} from './flags';
declare global {
interface Window {
ENABLED_EXPERIMENTS?: string[];
}
}
/**
* Flags service.
*
* Provides all related methods / properties regarding on feature flags.
*/
export class FlagsServiceImplementation implements FlagsService, Finalizable {
private readonly _experiments: Set<string>;
constructor() {
// stores all enabled experiments
this._experiments = this._loadExperiments();
}
finalize() {}
isEnabled(experimentId: string): boolean {
return this._experiments.has(experimentId);
}
_loadExperiments(): Set<string> {
return new Set(window.ENABLED_EXPERIMENTS ?? []);
}
get enabledExperiments() {
return [...this._experiments];
}
}