-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathneon.js
234 lines (201 loc) · 7.82 KB
/
neon.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
if (typeof global === "undefined") {
global = window;
}
global.Interface = function Interface(nameOrNameSpace, name) {
var nameSpace, interfaceName, factory;
nameSpace = (nameOrNameSpace && name) ? nameOrNameSpace : this;
interfaceName = (nameOrNameSpace && name) ? name :
(nameOrNameSpace) ? nameOrNameSpace : 'interface' + Math.random().toString();
factory = function(definition) {
definition.isInterface = true;
definition.name = interfaceName;
nameSpace[interfaceName] = definition;
return nameSpace[interfaceName];
};
return factory;
};
global.Module = function Module(nameOrNameSpace, name) {
var nameSpace, moduleName, factory, newModule;
nameSpace = (nameOrNameSpace && name) ? nameOrNameSpace : this;
moduleName = (nameOrNameSpace && name) ? name :
(nameOrNameSpace) ? nameOrNameSpace : 'module' + Math.random().toString();
newModule = {
moduleName : moduleName,
prototype : {},
__includedModules : [],
include : function(module) {
var property;
for (property in module) {
if (module.hasOwnProperty(property)
&& property !== 'prototype'
&& property !== 'isModule'
&& property !== '__includedModules'
&& property !== 'include'
&& property !== 'moduleName') {
newModule[property] = module[property];
}
}
if (module.hasOwnProperty('prototype') && module.prototype) {
for (property in module.prototype) {
if (module.prototype.hasOwnProperty(property)) {
newModule.prototype[property] = module.prototype[property];
}
}
}
else {
module.prototype = {};
}
this.__includedModules.push(module);
return this;
}
};
factory = function(definition){
var property;
newModule.isModule = true;
for (property in definition) {
if (definition.hasOwnProperty(property)
&& property !== 'prototype'
&& property !== 'isModule'
&& property !== '__includedModules'
&& property !== 'include'
&& property !== 'moduleName') {
newModule[property] = definition[property];
}
}
if (definition.hasOwnProperty('prototype') && definition.prototype) {
for (property in definition.prototype) {
if (definition.prototype.hasOwnProperty(property)) {
newModule.prototype[property] = definition.prototype[property];
}
}
}
nameSpace[moduleName] = newModule;
return nameSpace[moduleName];
};
factory.includes = function () {
for(var i = 0; i < arguments.length; i++){
newModule.include(arguments[i]);
}
return factory;
};
return factory;
};
global.Class = function Class(classNameOrNameSpace, className) {
var nameSpace, newClass, classFactory;
nameSpace = (classNameOrNameSpace && className) ? classNameOrNameSpace : global;
className = (classNameOrNameSpace && className) ? className :
(classNameOrNameSpace) ? classNameOrNameSpace : 'class' + Math.random().toString();
newClass = function() {
if (this.init) {
this.init.apply(this, arguments);
}
};
newClass.__descendants = [];
newClass.__implementedInterfaces = [];
newClass.__includedModules = [];
newClass.className = className;
newClass.include = function(module) {
var property;
for (property in module) {
if (module.hasOwnProperty(property)
&& property != 'prototype'
&& property != 'constructor'
&& property != 'isModule'
&& property != 'superClass'
&& property != 'include') {
newClass[property] = module[property];
}
}
if (module.hasOwnProperty('prototype') && module.prototype) {
for (property in module.prototype) {
if (module.prototype.hasOwnProperty(property)) {
newClass.prototype[property] = module.prototype[property];
}
}
} else {
module.prototype = {};
}
newClass.__includedModules.push(module);
return this;
};
classFactory = function(classDefinition) {
var i, il, j, jl, property, classPrototype = classDefinition.prototype;
if (classPrototype) {
for (property in classPrototype) {
if (classPrototype.hasOwnProperty(property)) {
newClass.prototype[property] = classPrototype[property];
}
}
delete classDefinition.prototype;
}
for (property in classDefinition) {
if (classDefinition.hasOwnProperty(property)) {
newClass[property] = classDefinition[property];
}
}
for (i = 0, il = newClass.__implementedInterfaces.length; i < il; i++) {
for (j = 0, jl = newClass.__implementedInterfaces[i].constructor.length; j < jl; j++) {
if (!newClass[ newClass.__implementedInterfaces[i].constructor[j] ]) {
console.log('must implement static ' + newClass.__implementedInterfaces[i].name);
break;
}
}
if (newClass.__implementedInterfaces[i].hasOwnProperty('prototype')
&& newClass.__implementedInterfaces[i].prototype) {
for (j = 0, jl = newClass.__implementedInterfaces[i].prototype.length; j < jl; j++) {
if (!newClass.prototype[newClass.__implementedInterfaces[i].prototype[j]]) {
console.log('must implement prototype ' + newClass.__implementedInterfaces[i].name);
break;
}
}
}
}
try {
if (Li && Li.ObjectSpy && Li.Spy) {
newClass.__objectSpy = new Li.ObjectSpy();
newClass.__objectSpy.spy(newClass);
newClass.__objectSpy.spy(newClass.prototype);
}
} catch (error) {}
nameSpace[className] = newClass;
return newClass;
};
classFactory.inherits = function(superClass) {
var i, inheritedClass;
newClass.superClass = superClass;
if (superClass.hasOwnProperty('__descendants')) {
superClass.__descendants.push(newClass);
}
inheritedClass = function() {
};
inheritedClass.prototype = superClass.prototype;
newClass.prototype = new inheritedClass();
newClass.prototype.constructor = newClass;
for (i in superClass) {
if (superClass.hasOwnProperty(i)
&& i != 'prototype'
&& i !== 'className'
&& i !== 'superClass'
&& i !== 'include'
&& i != '__descendants') {
newClass[i] = superClass[i];
}
}
delete this.inherits;
return this;
};
classFactory.ensures = function(interfaces) {
for (var i = 0; i < arguments.length; i++) {
newClass.__implementedInterfaces.push(arguments[i]);
}
delete this.ensures;
return classFactory;
};
classFactory.includes = function() {
for (var i = 0; i < arguments.length; i++) {
newClass.include(arguments[i]);
}
return classFactory;
};
return classFactory;
};