Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
export type Experiments = never;
export const AVAILABLE_EXPERIMENTS: Experiments[] = [ ];
export interface ExperimentOptions {
enabled?: Experiments[]
}
export type ExperimentsAction =
| { type: undefined }
| {
type: "EXPERIMENTS_ENABLE";
key: Experiments;
}
| {
type: "EXPERIMENTS_DISABLE";
key: Experiments;
};
export function experiments(
state = {} as ExperimentOptions,
action: ExperimentsAction
): ExperimentOptions {
switch (action.type) {
case "EXPERIMENTS_ENABLE":
return {
...state,
enabled: [
...(state.enabled ?? [])
.filter(x => AVAILABLE_EXPERIMENTS.includes(x))
.filter(v => v !== action.key),
action.key
]
};
case "EXPERIMENTS_DISABLE":
return {
...state,
enabled: state.enabled?.filter(v => v !== action.key)
.filter(x => AVAILABLE_EXPERIMENTS.includes(x))
};
default:
return state;
}
}