vsn 0.1.135 → 0.1.136
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/demo/vsn.js +2 -2
- package/dist/AST.d.ts +8 -3
- package/dist/AST.js +63 -21
- package/dist/AST.js.map +1 -1
- package/dist/DOM/AbstractDOM.d.ts +1 -0
- package/dist/DOM/AbstractDOM.js +9 -2
- package/dist/DOM/AbstractDOM.js.map +1 -1
- package/dist/Tag.js +3 -1
- package/dist/Tag.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/AST.ts +37 -4
- package/src/DOM/AbstractDOM.ts +11 -2
- package/src/Tag.ts +3 -1
- package/src/version.ts +1 -1
package/src/AST.ts
CHANGED
|
@@ -474,19 +474,52 @@ export interface ExecutionContext {
|
|
|
474
474
|
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
+
export class TreeCache {
|
|
478
|
+
cache: Map<string, Node> = new Map<string, Node>();
|
|
479
|
+
lastUsed: Map<string, number> = new Map<string, number>();
|
|
480
|
+
|
|
481
|
+
get(code: string) {
|
|
482
|
+
if (!this.cache.has(code))
|
|
483
|
+
return null;
|
|
484
|
+
|
|
485
|
+
this.lastUsed.set(code, Date.now());
|
|
486
|
+
return this.cache.get(code);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
set(code: string, node: Node) {
|
|
490
|
+
this.cache.set(code, node);
|
|
491
|
+
this.lastUsed.set(code, Date.now());
|
|
492
|
+
|
|
493
|
+
if (this.cache.size > 200) {
|
|
494
|
+
let toRemove = 20;
|
|
495
|
+
for (const [key, lastUsed] of Array.from(this.lastUsed.entries()).sort((a, b) => a[1] - b[1])) {
|
|
496
|
+
this.cache.delete(key);
|
|
497
|
+
this.lastUsed.delete(key);
|
|
498
|
+
toRemove--;
|
|
499
|
+
if (toRemove === 0)
|
|
500
|
+
break;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
has(code: string) {
|
|
506
|
+
return this.cache.has(code);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
477
510
|
export class Tree {
|
|
478
511
|
protected static executing: Set<ExecutionContext> = new Set<ExecutionContext>();
|
|
479
|
-
protected static cache:
|
|
512
|
+
protected static cache: TreeCache = new TreeCache();
|
|
480
513
|
protected _root: Node;
|
|
481
514
|
|
|
482
515
|
constructor(
|
|
483
516
|
public readonly code: string
|
|
484
517
|
) {
|
|
485
|
-
if (Tree.cache
|
|
486
|
-
this._root = Tree.cache
|
|
518
|
+
if (Tree.cache.has(code)) {
|
|
519
|
+
this._root = Tree.cache.get(code);
|
|
487
520
|
} else {
|
|
488
521
|
this.parse();
|
|
489
|
-
Tree.cache
|
|
522
|
+
Tree.cache.set(code, this._root);
|
|
490
523
|
}
|
|
491
524
|
}
|
|
492
525
|
|
package/src/DOM/AbstractDOM.ts
CHANGED
|
@@ -256,7 +256,10 @@ export abstract class AbstractDOM extends EventDispatcher {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
async buildTag<T extends Tag>(element: HTMLElement, returnExisting: boolean = false, cls: any = Tag): Promise<T> {
|
|
259
|
-
if (element[Tag.TaggedVariable])
|
|
259
|
+
if (element[Tag.TaggedVariable]) {
|
|
260
|
+
this.removedQueued(element);
|
|
261
|
+
return returnExisting ? element[Tag.TaggedVariable] : null;
|
|
262
|
+
}
|
|
260
263
|
if (element.tagName.toLowerCase() === 'slot')
|
|
261
264
|
cls = SlotTag;
|
|
262
265
|
else if (element.hasAttribute('slot'))
|
|
@@ -293,7 +296,7 @@ export abstract class AbstractDOM extends EventDispatcher {
|
|
|
293
296
|
|
|
294
297
|
for (const tag of tags) {
|
|
295
298
|
await tag.finalize();
|
|
296
|
-
this.
|
|
299
|
+
this.removedQueued(tag.element)
|
|
297
300
|
}
|
|
298
301
|
|
|
299
302
|
for (const tag of tags) {
|
|
@@ -306,6 +309,12 @@ export abstract class AbstractDOM extends EventDispatcher {
|
|
|
306
309
|
}
|
|
307
310
|
}
|
|
308
311
|
|
|
312
|
+
removedQueued(element: HTMLElement) {
|
|
313
|
+
const index = this.queued.indexOf(element);
|
|
314
|
+
if (index > -1)
|
|
315
|
+
this.queued.splice(index, 1);
|
|
316
|
+
}
|
|
317
|
+
|
|
309
318
|
async buildFrom(ele: any, isRoot: boolean = false, forComponent: boolean = false): Promise<Tag[]> {
|
|
310
319
|
if (isRoot) {
|
|
311
320
|
this.rootElement.setAttribute('vsn-root', '');
|
package/src/Tag.ts
CHANGED
|
@@ -810,8 +810,10 @@ export class Tag extends DOMObject {
|
|
|
810
810
|
|
|
811
811
|
deconstruct() {
|
|
812
812
|
const dom = this.dom || DOM.instance;
|
|
813
|
-
if (dom)
|
|
813
|
+
if (dom) {
|
|
814
|
+
dom.removedQueued(this.element);
|
|
814
815
|
dom.deregisterElementInRoot(this);
|
|
816
|
+
}
|
|
815
817
|
this.removeAllEventHandlers();
|
|
816
818
|
this.attributes.forEach(attr => attr.deconstruct());
|
|
817
819
|
this.attributes.clear();
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.136';
|
|
2
2
|
|