forked from alibaba/lowcode-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.ts
More file actions
70 lines (56 loc) · 1.6 KB
/
controller.ts
File metadata and controls
70 lines (56 loc) · 1.6 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { set, get, has } from 'lodash';
import { EventEmitter } from 'events';
export type IInjectConfig = {
[pluginName: string]: {
[resourceName: string]: {
[viewName: string]: boolean;
} | boolean;
global?: boolean;
};
};
export class InjectConfig {
_config: IInjectConfig = JSON.parse(localStorage.getItem('___inject_config___') || '{}');
event: EventEmitter = new EventEmitter()
get config() {
return this._config;
}
onChange(fn: (config: IInjectConfig) => void) {
this.event.on('changeConfig', fn);
return () => {
this.event.off('changeConfig', fn)
}
}
set(pluginName, resourceName, viewName, injected: boolean) {
if (!viewName) {
set(this._config, [pluginName, resourceName], injected);
this._config = {
...this._config,
}
this.event.emit('changeConfig', this.config);
return;
}
set(this._config, [pluginName, resourceName, viewName], injected);
this._config = {
...this._config,
}
this.event.emit('changeConfig', this.config);
}
get(pluginName, resourceName, viewName?) {
if (!viewName) {
return get(this._config, [pluginName, resourceName], false)
}
return get(this._config, [pluginName, resourceName, viewName], false)
}
has(pluginName, resourceName, viewName?) {
if (!viewName) {
return has(this._config, [pluginName, resourceName])
}
return has(this._config, [pluginName, resourceName, viewName])
}
clearAll() {
this._config = {};
}
save() {
localStorage.setItem('___inject_config___', JSON.stringify(this._config));
}
}