-
Notifications
You must be signed in to change notification settings - Fork 5
/
ezy-setup.js
73 lines (62 loc) · 1.8 KB
/
ezy-setup.js
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
71
72
73
class EzySetup {
constructor(handlerManager) {
this.handlerManager = handlerManager;
this.appSetups = {};
this.pluginSetups = {};
}
addDataHandler(cmd, dataHandler) {
this.handlerManager.addDataHandler(cmd, dataHandler);
return this;
}
addEventHandler(eventType, eventHandler) {
this.handlerManager.addEventHandler(eventType, eventHandler);
return this;
}
setupApp(appName) {
var appSetup = this.appSetups[appName];
if (!appSetup) {
var appDataHandlers =
this.handlerManager.getAppDataHandlers(appName);
appSetup = new EzyAppSetup(appDataHandlers, this);
this.appSetups[appName] = appSetup;
}
return appSetup;
}
setupPlugin(pluginName) {
var pluginSetup = this.pluginSetups[pluginName];
if (!pluginSetup) {
var pluginDataHandlers =
this.handlerManager.getPluginDataHandlers(pluginName);
pluginSetup = new EzyPluginSetup(pluginDataHandlers, this);
this.pluginSetups[pluginName] = pluginSetup;
}
return pluginSetup;
}
}
class EzyAppSetup {
constructor(dataHandlers, parent) {
this.parent = parent;
this.dataHandlers = dataHandlers;
}
addDataHandler(cmd, dataHandler) {
this.dataHandlers.addHandler(cmd, dataHandler);
return this;
}
done() {
return this.parent;
}
}
class EzyPluginSetup {
constructor(dataHandlers, parent) {
this.parent = parent;
this.dataHandlers = dataHandlers;
}
addDataHandler(cmd, dataHandler) {
this.dataHandlers.addHandler(cmd, dataHandler);
return this;
}
done() {
return this.parent;
}
}
export default EzySetup;