-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
Copy pathApplication.mjs
144 lines (125 loc) · 3.38 KB
/
Application.mjs
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import Base from './Base.mjs';
import ClassSystemUtil from '../util/ClassSystem.mjs';
/**
* @class Neo.controller.Application
* @extends Neo.controller.Base
*/
class Application extends Base {
/**
* True automatically applies the core.Observable mixin
* @member {Boolean} observable=true
* @static
*/
static observable = true
static config = {
/**
* @member {String} className='Neo.controller.Application'
* @protected
*/
className: 'Neo.controller.Application',
/**
* @member {String} ntype='application'
* @protected
*/
ntype: 'application',
/**
* @member {String|null} appThemeFolder=null
*/
appThemeFolder: null,
/**
* @member {Neo.component.Base} mainView_=null
*/
mainView_: null,
/**
* @member {Boolean} mounted=false
* @protected
*/
mounted: false,
/**
* @member {String} name='MyApp'
*/
name: 'MyApp',
/**
* @member {String} parentId='document.body'
*/
parentId: 'document.body',
/**
* @member {Boolean} rendered=false
* @protected
*/
rendered: false,
/**
* @member {Boolean} rendering=false
* @protected
*/
rendering: false,
/**
* @member {Number|null} windowId=null
*/
windowId: null
}
/**
* @param {Object} config
*/
construct(config) {
// to guarantee that the main view can access Neo.apps at any point,
// we need to trigger its assignment at the end of the ctor.
let mainView = config.mainView;
delete config.mainView;
super.construct(config);
let me = this;
me.windowId = Neo.config.windowId;
Neo.apps = Neo.apps || {};
Neo.apps[me.name] = me;
Neo.currentWorker.registerApp(me.name);
if (mainView) {
me.mainView = mainView
}
}
/**
* Triggered after the mainView config got changed
* @param {Neo.component.Base} value
* @param {Neo.component.Base|null} oldValue
* @protected
*/
async afterSetMainView(value, oldValue) {
if (value) {
let me = this;
// short delay to ensure changes from onHashChange() got applied
await me.timeout(Neo.config.hash ? 200 : 10);
await value.render(true)
}
}
/**
* Triggered before the mainView config gets changed.
* @param {Object} value
* @param {Object} oldValue
* @returns {Neo.component.Base|null}
* @protected
*/
beforeSetMainView(value, oldValue) {
if (value) {
return ClassSystemUtil.beforeSetInstance(value, null, {
appName : this.name,
parentId: this.parentId,
windowId: Neo.config.windowId
})
}
return null
}
/**
* Unregister the app from the CSS map
* @param args
*/
destroy(...args) {
Neo.currentWorker.removeAppFromThemeMap(this.name);
super.destroy(...args)
}
}
Application = Neo.setupClass(Application);
// convenience shortcut
Neo.app = config => Neo.create({
module: Application,
...config
});
export default Application;