-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
ui.ts
48 lines (41 loc) · 1.02 KB
/
ui.ts
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
44
45
46
47
48
/**
* This module maintains various ephemeral UI settings. These settings should be
* maintained within a session, but not saved between sessions.
*/
import "../util/object-assign";
import { Action, PayloadAction } from "../interfaces/action";
const SET_UI_VALUE = "cockroachui/ui/SET_UI_VALUE";
export class UISetting {
key: string;
value: any;
}
export class UISettingsDict {
[key: string]: any;
}
export default function reducer(state: UISettingsDict, action: Action): UISettingsDict {
if (action === undefined) {
return;
}
if (state === undefined) {
state = {};
}
switch (action.type) {
case SET_UI_VALUE:
let { payload } = action as PayloadAction<UISetting>;
return Object.assign({}, state, {[payload.key]: payload.value});
default:
return state;
}
}
/**
* Set an ephemeral UI setting.
*/
export function setUISetting(key: string, value: any): PayloadAction<UISetting> {
return {
type: SET_UI_VALUE,
payload: {
key: key,
value: value,
},
};
}