feat(mobx): add experiments store

This commit is contained in:
Paul
2021-12-11 13:23:01 +00:00
parent 835609dbbd
commit fa009c43e3
4 changed files with 33 additions and 31 deletions

View File

@@ -5,6 +5,7 @@ import { useContext } from "preact/hooks";
import Auth from "./stores/Auth";
import Draft from "./stores/Draft";
import Experiments from "./stores/Experiments";
import LocaleOptions from "./stores/LocaleOptions";
interface StoreDefinition {
@@ -22,6 +23,7 @@ export default class State {
auth: Auth;
draft: Draft;
locale: LocaleOptions;
experiments: Experiments;
/**
* Construct new State.
@@ -30,6 +32,7 @@ export default class State {
this.auth = new Auth();
this.draft = new Draft();
this.locale = new LocaleOptions();
this.experiments = new Experiments();
makeAutoObservable(this);
}

View File

@@ -10,7 +10,7 @@ export type Experiment = "dummy" | "theme_shop";
/**
* Currently active experiments.
*/
export const AVAILABLE_EXPERIMENTS: Experiment[] = ["theme_shop"];
export const AVAILABLE_EXPERIMENTS: Experiment[] = ["dummy", "theme_shop"];
/**
* Definitions for experiments listed by {@link Experiment}.
@@ -84,6 +84,19 @@ export default class Experiments implements Persistent<Data> {
this.enabled.delete(experiment);
}
/**
* Set the state of an experiment.
* @param key Experiment
* @param enabled Whether this experiment is enabled.
*/
@computed setEnabled(key: Experiment, enabled: boolean): void {
if (enabled) {
this.enable(key);
} else {
this.disable(key);
}
}
/**
* Reset and disable all experiments.
*/