dothtml 4.8.5 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{jest.config.js → jest.config.ts} +19 -16
- package/lib/arg-callback-obj.d.ts +29 -0
- package/lib/built-in-components/nav-link.d.ts +8 -0
- package/lib/built-in-components/router.d.ts +57 -0
- package/lib/component.d.ts +73 -0
- package/lib/dot-component-legacy.d.ts +0 -0
- package/lib/dot-document.d.ts +0 -0
- package/lib/dot-util.d.ts +13 -0
- package/lib/dot.d.ts +5 -0
- package/lib/dothtml.d.ts +21 -0
- package/lib/dothtml.js +2 -0
- package/lib/dothtml.js.LICENSE.txt +1 -0
- package/lib/err.d.ts +2 -0
- package/lib/event-bus.d.ts +10 -0
- package/lib/i-dot.d.ts +674 -0
- package/lib/i-dotcss.d.ts +827 -0
- package/lib/node-polyfill.d.ts +2 -0
- package/lib/observable-array.d.ts +49 -0
- package/lib/style-builder.d.ts +3 -0
- package/package.json +11 -5
- package/readme.md +3 -2
- package/src/{arg-callback-obj.js → arg-callback-obj.ts} +18 -6
- package/src/built-in-components/nav-link.ts +21 -0
- package/src/built-in-components/router.ts +315 -0
- package/src/component.ts +369 -0
- package/src/dot-component-legacy.ts +79 -0
- package/src/dot-document.ts +0 -0
- package/src/dot-util.ts +33 -0
- package/src/dot.ts +1147 -0
- package/src/dothtml.ts +33 -0
- package/src/err.ts +22 -0
- package/src/event-bus.ts +39 -0
- package/src/i-dot.ts +787 -0
- package/src/i-dotcss.ts +918 -0
- package/src/node-polyfill.ts +11 -0
- package/src/{observable-array.js → observable-array.ts} +10 -5
- package/src/{style-builder.js → style-builder.ts} +219 -183
- package/tsconfig.json +99 -0
- package/unittests/advanced-bindings.test.ts +421 -0
- package/unittests/{array-evaluation.test.js → array-evaluation.test.ts} +1 -1
- package/unittests/{basic-functionality.test.js → basic-functionality.test.ts} +14 -10
- package/unittests/class-binding.test.ts +227 -0
- package/unittests/component-decorator.-.ts +14 -0
- package/unittests/components-data.test.ts +153 -0
- package/unittests/components.test.ts +257 -0
- package/unittests/computed.test.ts +35 -0
- package/unittests/{core.js → core.ts} +5 -2
- package/unittests/element-and-attribute-coverage.test.ts +472 -0
- package/unittests/hooks.test.ts +67 -0
- package/unittests/immutable-if.test.ts +19 -0
- package/unittests/input-bindings.test.ts +166 -0
- package/unittests/integration.test.ts +5 -0
- package/unittests/{iterations.test.js → iterations.test.ts} +5 -5
- package/unittests/logic.test.ts +18 -0
- package/unittests/refs.test.ts +36 -0
- package/unittests/routing.-.ts +56 -0
- package/unittests/{scopes.test.js → scopes.test.ts} +5 -5
- package/unittests/special-tags.test.ts +39 -0
- package/unittests/styles.test.ts +9 -0
- package/unittests/{testpage.js → testpage.ts} +2 -0
- package/unittests/{wait.test.js → wait.test.ts} +8 -5
- package/webpack.config.js +13 -1
- package/lib/dothtml.min.js +0 -1
- package/src/component.js +0 -305
- package/src/err.js +0 -20
- package/src/event-bus.js +0 -40
- package/src/index.js +0 -1453
- package/src/util.js +0 -13
- package/unittests/advanced-bindings.test.js +0 -386
- package/unittests/class-binding.test.js +0 -53
- package/unittests/components-data.test.js +0 -97
- package/unittests/components.test.js +0 -151
- package/unittests/computed.test.js +0 -36
- package/unittests/hooks.test.js +0 -57
- package/unittests/immutable-if.test.js +0 -15
- package/unittests/input-bindings.test.js +0 -155
- package/unittests/integration.test.js +0 -6
- package/unittests/logic.test.js +0 -18
- package/unittests/routing.-.js +0 -56
- package/unittests/special-tags.test.js +0 -32
package/src/component.ts
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import ObservableArray from "./observable-array";
|
|
2
|
+
import dot from "./dot";
|
|
3
|
+
import { ClassPrefix, eachK, GlobalComponentStack, isF, sT } from "./dot-util";
|
|
4
|
+
import ERR from "./err";
|
|
5
|
+
import { IDotDocument, IDotElement, IDotElementDocument, IDotGenericElement } from "./i-dot";
|
|
6
|
+
import { ArgCallback, ArrayArgCallback, AttrArgCallback } from "./arg-callback-obj";
|
|
7
|
+
import IDotCss from "./i-dotcss";
|
|
8
|
+
|
|
9
|
+
interface IPropertyContainer{
|
|
10
|
+
activePropConstructor: Function;
|
|
11
|
+
propDependencies: {[key: string]: Array<ArgCallback>}
|
|
12
|
+
rawProps: {[key: string]: any}
|
|
13
|
+
activeProps: {[key: string]: any}
|
|
14
|
+
bindings: {[key: string]: Array<{
|
|
15
|
+
element: HTMLElement
|
|
16
|
+
}>}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
abstract class Component{
|
|
21
|
+
|
|
22
|
+
static initializeComponent<T extends Component>(obj: T): void{
|
|
23
|
+
if(!(obj.constructor as any).__dotComponentInitialized) {
|
|
24
|
+
(obj.constructor as any).__dotComponentInitialized = true;
|
|
25
|
+
|
|
26
|
+
// Additional generic logic that should run once per component.
|
|
27
|
+
(obj.constructor as any).__dotClassNumb = ClassPrefix.next;
|
|
28
|
+
(obj.constructor as any).__activePropContainer = function ActivePropContainer(obj){
|
|
29
|
+
this.__component = obj;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
eachK(obj.props, (k,v) => {
|
|
33
|
+
Component.createProp((obj.constructor as any).__activePropContainer, k);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static build<T extends Component>(obj: T): Element{
|
|
40
|
+
Component.initializeComponent(obj);
|
|
41
|
+
|
|
42
|
+
GlobalComponentStack.push(obj);
|
|
43
|
+
obj.created && obj.created(...obj.__args);
|
|
44
|
+
|
|
45
|
+
if(obj.__built) ERR("CB");
|
|
46
|
+
obj.__built = true;
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
obj.__propContainer = {
|
|
51
|
+
activePropConstructor: (obj.constructor as any).__activePropContainer,
|
|
52
|
+
rawProps: obj.props || {},
|
|
53
|
+
activeProps: new (obj.constructor as any).__activePropContainer(obj),
|
|
54
|
+
propDependencies: {},
|
|
55
|
+
bindings: {}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// eachK(obj.props, (k,v) => {
|
|
59
|
+
// // Initialize it.
|
|
60
|
+
// cc.__propContainer.activeProps[k] = cc.__propContainer.rawProps[k];
|
|
61
|
+
// });
|
|
62
|
+
obj.props = obj.__propContainer.activeProps;
|
|
63
|
+
|
|
64
|
+
eachK(obj.__propContainer.rawProps, (k,v) => {
|
|
65
|
+
obj.__propContainer.bindings[k] = []
|
|
66
|
+
obj.props[k] = v;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// function ComputedContainer(){
|
|
70
|
+
// };
|
|
71
|
+
// let cc = new ComputedContainer();
|
|
72
|
+
|
|
73
|
+
// eachK(obj.computed, function(k, v){
|
|
74
|
+
// isF(v) ? v : ERR("XF", "computed")
|
|
75
|
+
// //createProp(k, CC);
|
|
76
|
+
// ComputedContainer.prototype[k] = v;
|
|
77
|
+
// Object.defineProperty(ComputedContainer.prototype, k, {
|
|
78
|
+
// enumerable: true,
|
|
79
|
+
// get: function(){
|
|
80
|
+
// // This was commented out pre-ts.
|
|
81
|
+
// //configureDependency(v(), this, k);
|
|
82
|
+
// return v.call(obj);
|
|
83
|
+
// }
|
|
84
|
+
// });
|
|
85
|
+
// });
|
|
86
|
+
// obj.computed = cc;
|
|
87
|
+
|
|
88
|
+
Component.initializeEventHandlers(obj);
|
|
89
|
+
|
|
90
|
+
let ret = obj.builder(...obj.__args);
|
|
91
|
+
|
|
92
|
+
let lst = ret.getLast();
|
|
93
|
+
(!lst || (lst.parentNode.childNodes.length > 1)) && ERR("C#", obj.name || obj.constructor.name || "(unnamed obj)");
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
// Some weird ass logic to support legacy named components and the new syntax.
|
|
98
|
+
// if(classNumb || n) ret = (obj instanceof DotDocument ? obj : dot)._appendOrCreateDocument(dot.scopeClass(classNumb, ret));
|
|
99
|
+
// ret = ret.scopeClass(ret, (obj.constructor as any).__dotClassNumb);
|
|
100
|
+
|
|
101
|
+
obj["__$el"] = obj.$el || lst;
|
|
102
|
+
obj.$el["__dothtml_component"] = obj;
|
|
103
|
+
|
|
104
|
+
// TODO: would there be a way to not have to create obj function for each instance?
|
|
105
|
+
if(obj.style) {
|
|
106
|
+
// obj will be the officially supported way to use dothtml.
|
|
107
|
+
obj.$styleBuilder = function(){
|
|
108
|
+
// dot.css.scopeToEl(obj.$el, !obj.__stylesSet);
|
|
109
|
+
dot.css.scopeToEl(obj.$el);
|
|
110
|
+
if(!obj.__stylesSet){
|
|
111
|
+
dot.css.cacheScopedStaticStyles(obj.$el);
|
|
112
|
+
obj.__stylesSet = true;
|
|
113
|
+
}
|
|
114
|
+
dot.css.clearDynamicStyles(obj.$el);
|
|
115
|
+
obj.style(dot.css);
|
|
116
|
+
dot.css.unscope();
|
|
117
|
+
}
|
|
118
|
+
obj.$updateStyles();
|
|
119
|
+
//styler();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
obj.built && obj.built();
|
|
123
|
+
|
|
124
|
+
// TODO: would be great to do this without a timer, once the DOM is updated.
|
|
125
|
+
// May require some type of queueing system within dot.
|
|
126
|
+
obj.ready && sT(()=>{
|
|
127
|
+
GlobalComponentStack.push(obj);
|
|
128
|
+
obj.ready();
|
|
129
|
+
GlobalComponentStack.pop()
|
|
130
|
+
}, 0);
|
|
131
|
+
|
|
132
|
+
GlobalComponentStack.pop();
|
|
133
|
+
|
|
134
|
+
return obj.$el;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static initializeEventHandlers(obj){
|
|
138
|
+
if(!obj.__eventsInitialized){
|
|
139
|
+
obj.__eventsInitialized = true;
|
|
140
|
+
eachK(obj.events, (k,v) => {
|
|
141
|
+
obj.events[k] = function(){
|
|
142
|
+
for(let f of obj.events[k]["__handlers"]){
|
|
143
|
+
f.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
obj.events[k]["__handlers"] = [];
|
|
148
|
+
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
static createProp(activePropContainer: Function, name: string){
|
|
154
|
+
// var dependencies = [];
|
|
155
|
+
Object.defineProperty(activePropContainer.prototype, name, {
|
|
156
|
+
configurable: false,
|
|
157
|
+
enumerable: false,
|
|
158
|
+
get: function() {
|
|
159
|
+
dot["__lastProp"] = name;
|
|
160
|
+
dot["__lastIndex"] = null;
|
|
161
|
+
dot["__lastComponent"] = this.__component;
|
|
162
|
+
|
|
163
|
+
let rawProp = this.__component.__propContainer.rawProps[name];
|
|
164
|
+
Component.configureDependency(this.__component, name);
|
|
165
|
+
return rawProp;
|
|
166
|
+
},
|
|
167
|
+
set: function(value) {
|
|
168
|
+
// TODO: if this value is set, get the list of dependencies, and update them by calling their dot argument callbacks.
|
|
169
|
+
let propVal = value;
|
|
170
|
+
if(value instanceof Array){
|
|
171
|
+
propVal = new ObservableArray(value);
|
|
172
|
+
propVal.addEventListener("read",e=>{
|
|
173
|
+
|
|
174
|
+
dot["__lastIndex"] = e.index;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
this.__component.__propContainer.rawProps[name] = propVal;
|
|
178
|
+
for(let b of this.__component.__propContainer.bindings[name]){
|
|
179
|
+
dot(b.element).as(dot.input).setVal(propVal);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
Component.updateProp(this.__component, name);
|
|
183
|
+
|
|
184
|
+
return propVal;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
static configureDependency(cc: Component, name: string){
|
|
192
|
+
// TODO: verify that there is no memory leak!!
|
|
193
|
+
var cb: ArgCallback = dot["__currentArgCallback"][dot["__currentArgCallback"].length-1];
|
|
194
|
+
if(cb){
|
|
195
|
+
// This means this getter is being used during the invocation of an arg callback.
|
|
196
|
+
// Add it to a collection so that when the value is set, the appropriate component will update.
|
|
197
|
+
let rawProp = cc.__propContainer.rawProps[name];
|
|
198
|
+
|
|
199
|
+
if(rawProp instanceof ObservableArray){
|
|
200
|
+
(rawProp as any).addEventListener("itemadded", function(e) {
|
|
201
|
+
// TODO: More test cases to create:
|
|
202
|
+
// TODO: what about rendering the list length or something?
|
|
203
|
+
// TODO: what about a computed field based on length?
|
|
204
|
+
if(cb instanceof ArrayArgCallback) {
|
|
205
|
+
cb.dotTarget._appendOrCreateDocument(cb.f(e.item, e.index), undefined, e.index);
|
|
206
|
+
}
|
|
207
|
+
else if(cb as AttrArgCallback) {
|
|
208
|
+
Component.updateProp(cc, name);
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
(rawProp as any).addEventListener("itemset", function(e) {
|
|
213
|
+
if(cb instanceof ArrayArgCallback) {
|
|
214
|
+
var p = (cb.dotTarget as any).__document;
|
|
215
|
+
var el = p.childNodes[e.index];
|
|
216
|
+
p.removeChild(el);
|
|
217
|
+
cb.dotTarget._appendOrCreateDocument(cb.f(e.item, e.index), undefined, e.index);
|
|
218
|
+
}
|
|
219
|
+
else if(cb as AttrArgCallback) {
|
|
220
|
+
Component.updateProp(cc, name);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
(rawProp as any).addEventListener("itemremoved", function(e) {
|
|
227
|
+
if(cb instanceof ArrayArgCallback) {
|
|
228
|
+
(cb.dotTarget as any).__document.removeChild((cb.dotTarget as any).__document.childNodes[e.index]);
|
|
229
|
+
}
|
|
230
|
+
else if(cb as AttrArgCallback) {
|
|
231
|
+
Component.updateProp(cc, name);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
else{
|
|
236
|
+
}
|
|
237
|
+
var ar = cc.__propContainer.propDependencies[name];
|
|
238
|
+
if(!ar) ar = cc.__propContainer.propDependencies[name] = [];
|
|
239
|
+
ar.push(cb);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
static updateProp(obj: Component, name: string){
|
|
244
|
+
let ar = obj.__propContainer.propDependencies[name];
|
|
245
|
+
let value = obj.__propContainer.rawProps[name];
|
|
246
|
+
|
|
247
|
+
// // {f:contentCallback,startNode:startNode, endNode:endNode,condition:condition}
|
|
248
|
+
let updateStyles = false;
|
|
249
|
+
for(let i = 0; i < (ar||[]).length; i++){
|
|
250
|
+
let arg = ar[i];
|
|
251
|
+
// TODO: this could be used to update attributes.
|
|
252
|
+
// But right now that relies exclusively on function setters. It's a bit weird.
|
|
253
|
+
arg.updateContent(dot, value);
|
|
254
|
+
|
|
255
|
+
if(arg instanceof AttrArgCallback && arg.attr == "class"){
|
|
256
|
+
updateStyles = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if(updateStyles) obj.$updateStyles();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
constructor(...args: Array<any>){
|
|
264
|
+
this.__args = args;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* A function returning DOThtml (required).
|
|
269
|
+
*/
|
|
270
|
+
abstract builder(...args: Array<any>): IDotElement;
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
*
|
|
274
|
+
*/
|
|
275
|
+
props: {[key: string]: any};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* A series of events that can be raised from inside the component.
|
|
279
|
+
*/
|
|
280
|
+
events: {[key: string]: (... params: Array<any>)=>void};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* An optional function that gets called before the component is created, scoped to the new component object.
|
|
284
|
+
*/
|
|
285
|
+
created(...args: Array<any>): void{}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* An optional function called after the element has been added. One parameter will be provided containing the added element.
|
|
289
|
+
*/
|
|
290
|
+
ready(): void{}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* An optional function called before the component is deleted.
|
|
294
|
+
*/
|
|
295
|
+
deleting(): void{}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* An optional function called after the component is deleted.
|
|
299
|
+
*/
|
|
300
|
+
deleted(): void{}
|
|
301
|
+
/**
|
|
302
|
+
* An optional function called after the component is built.
|
|
303
|
+
*/
|
|
304
|
+
built(): void{}
|
|
305
|
+
|
|
306
|
+
on(event: string, handler: Function): void{
|
|
307
|
+
Component.initializeEventHandlers(this);
|
|
308
|
+
|
|
309
|
+
let e = this.events && this.events[event];
|
|
310
|
+
if(!e) ERR("UE", event);
|
|
311
|
+
let handlers = e["__handlers"] as Array<Function>;
|
|
312
|
+
if(handlers.indexOf(handler) == -1){
|
|
313
|
+
handlers.push(handler);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
off(event: string, handler: Function): void{
|
|
317
|
+
let e = this.events && this.events[event];
|
|
318
|
+
if(!e) ERR("UE", event);
|
|
319
|
+
let handlers = e["__handlers"] as Array<Function>;
|
|
320
|
+
let i = handlers.indexOf(handler);
|
|
321
|
+
if(i > -1){
|
|
322
|
+
handlers.splice(i, 1);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private __$el: HTMLElement;
|
|
327
|
+
private __built = false;
|
|
328
|
+
private __stylesSet = false;
|
|
329
|
+
private __eventsInitialized: boolean = false;
|
|
330
|
+
private __propContainer: IPropertyContainer;
|
|
331
|
+
private __args: Array<any>;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* The main element of this component - automatically set after the builder is called.
|
|
335
|
+
*/
|
|
336
|
+
get $el(): HTMLElement{
|
|
337
|
+
return this.__$el;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
$refs: {[key: string]: Element} = {};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Name of the component (optional). If provided, dot and the VDBO will be extended.
|
|
344
|
+
*/
|
|
345
|
+
name: string;
|
|
346
|
+
/**
|
|
347
|
+
* An optional function that is called after builder that stylizes the component using a scoped style builder.
|
|
348
|
+
*/
|
|
349
|
+
style?(styleBuilder: IDotCss): void;
|
|
350
|
+
|
|
351
|
+
// constructor(params: ComponentParams){
|
|
352
|
+
// this.name = params.name;
|
|
353
|
+
// }
|
|
354
|
+
|
|
355
|
+
$styleBuilder?: Function;
|
|
356
|
+
|
|
357
|
+
$updateStyles(){
|
|
358
|
+
this.$styleBuilder && this.$styleBuilder();
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
export default Component;
|
|
363
|
+
|
|
364
|
+
// Eventually we'd like to set this up. Might be overkill.
|
|
365
|
+
// function component<T extends { new (...args: any[]): {} }>(constructor: T) {
|
|
366
|
+
// return class extends constructor {
|
|
367
|
+
//
|
|
368
|
+
// };
|
|
369
|
+
// }
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// import { ClassPrefix, eachK, isF, str } from "./dot-util";
|
|
2
|
+
// import ERR from "./err";
|
|
3
|
+
// import ObservableArray from "./observable-array";
|
|
4
|
+
// import { AttrArgCallback } from "./arg-callback-obj";
|
|
5
|
+
|
|
6
|
+
// /** How it works:
|
|
7
|
+
// *
|
|
8
|
+
// * DotComponent represents the prototype for all components.
|
|
9
|
+
// * You create a component with dot.component().
|
|
10
|
+
// * This creates a new class (CC), which acts as the prototype to that component.
|
|
11
|
+
// * The prototype of CC is set to a new DotComponent.
|
|
12
|
+
// * Instantiating the component creates a new CC.
|
|
13
|
+
// * This CC is the `this` for each method of the component.
|
|
14
|
+
// *
|
|
15
|
+
// *
|
|
16
|
+
// * */
|
|
17
|
+
|
|
18
|
+
// /** How computed props work.
|
|
19
|
+
// *
|
|
20
|
+
// * If a computed property has a dependency on a regular property,
|
|
21
|
+
// * assigning the computed property to an element will cause the regular property's getter to trigger, establishing the dependency.
|
|
22
|
+
// * */
|
|
23
|
+
|
|
24
|
+
// function DotComponent(){
|
|
25
|
+
// this.$el = null;
|
|
26
|
+
// this.$refs = {};
|
|
27
|
+
// this.__handlers = {};
|
|
28
|
+
// }
|
|
29
|
+
|
|
30
|
+
// DotComponent.prototype.__addHandler = function(eventName, event){
|
|
31
|
+
// var h = this.__handlers[eventName];
|
|
32
|
+
// if(!h) h = this.__handlers[eventName] = [];
|
|
33
|
+
// h.push(event);
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
// var dot, _p, _D;
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// /**
|
|
45
|
+
|
|
46
|
+
// */
|
|
47
|
+
// export function addComponent(prms: ComponentParams){
|
|
48
|
+
|
|
49
|
+
// // Setting this potentially allows automatic code completion to get the method signature from builder.
|
|
50
|
+
// // var comp = prms.builder;
|
|
51
|
+
|
|
52
|
+
// let n = prms.name;
|
|
53
|
+
|
|
54
|
+
// n && (componentNames[n] = 1);
|
|
55
|
+
// var CC = function(){
|
|
56
|
+
// DotComponent.call(this);
|
|
57
|
+
// this.rawProps = {};
|
|
58
|
+
// this.__propDependencies = {};
|
|
59
|
+
// this.__prms = prms;
|
|
60
|
+
// }
|
|
61
|
+
// CC.prototype = Object.create(DotComponent.prototype);
|
|
62
|
+
// CC.prototype.constructor = CC;
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
// prms.registered && prms.registered.apply(CC.prototype);
|
|
69
|
+
|
|
70
|
+
// return comp;
|
|
71
|
+
// };
|
|
72
|
+
|
|
73
|
+
// // export function removeComponent(name){
|
|
74
|
+
// // if(componentNames[name]){
|
|
75
|
+
// // delete componentNames[name];
|
|
76
|
+
// // delete dot[name];
|
|
77
|
+
// // delete _p[name];
|
|
78
|
+
// // }
|
|
79
|
+
// // }
|
|
File without changes
|
package/src/dot-util.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Polyfill for Object.keys(...).forEach.
|
|
2
|
+
|
|
3
|
+
import type Component from "./component";
|
|
4
|
+
|
|
5
|
+
export function eachK(obj, cb){
|
|
6
|
+
if(obj){
|
|
7
|
+
var lst = Object.keys(obj);
|
|
8
|
+
for(var i = 0; i < lst.length; i++) cb(lst[i], obj[lst[i]]);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function isF(v){
|
|
13
|
+
return v && v.constructor && v.call && v.apply;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const sT = setTimeout;
|
|
17
|
+
export function str(s: number,v?:number){return (s||"").toString(v)} // This function seems really weird.
|
|
18
|
+
|
|
19
|
+
class _ClassPrefix{
|
|
20
|
+
private current: number = 0x10000;
|
|
21
|
+
|
|
22
|
+
reset(){
|
|
23
|
+
this.current = 0x10000;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get next(): number{
|
|
27
|
+
return this.current++;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const ClassPrefix = new _ClassPrefix()
|
|
32
|
+
|
|
33
|
+
export const GlobalComponentStack: Array<Component> = [];
|