mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
feat(mobx): add experiments store
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user