flinker-dom 1.1.0 → 1.1.2
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/dist/esm/components.js +59 -34
- package/dist/types/components.d.ts +2 -1
- package/package.json +1 -1
package/dist/esm/components.js
CHANGED
|
@@ -4,11 +4,7 @@ export class UIComponent {
|
|
|
4
4
|
constructor(tag) {
|
|
5
5
|
this.unsubscribeColl = [];
|
|
6
6
|
this.reactions = [];
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* Rendering
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
7
|
+
// Rendering
|
|
12
8
|
this.willDomUpdate = false;
|
|
13
9
|
this.affectSet = new Set();
|
|
14
10
|
this.props = {};
|
|
@@ -511,54 +507,83 @@ export class List extends UIComponent {
|
|
|
511
507
|
}
|
|
512
508
|
items(fn) {
|
|
513
509
|
this._itemsFn = fn;
|
|
510
|
+
this.render('recreateChildren');
|
|
514
511
|
return this;
|
|
515
512
|
}
|
|
516
513
|
itemRenderer(fn) {
|
|
517
514
|
this._itemRenderer = fn;
|
|
515
|
+
this.render('recreateChildren');
|
|
518
516
|
return this;
|
|
519
517
|
}
|
|
520
518
|
itemHash(fn) {
|
|
521
519
|
this._itemHashFn = fn;
|
|
520
|
+
this.render('recreateChildren');
|
|
522
521
|
return this;
|
|
523
522
|
}
|
|
524
|
-
|
|
525
|
-
|
|
523
|
+
updateDom() {
|
|
524
|
+
if (this.isDestroyed)
|
|
525
|
+
return;
|
|
526
|
+
if (!this.willDomUpdate)
|
|
527
|
+
return;
|
|
528
|
+
this.willDomUpdate = false;
|
|
526
529
|
if (this.affectSet.has('affectsProps')) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
530
|
+
this.updateProps();
|
|
531
|
+
if (this.props.visible === false) {
|
|
532
|
+
this.dom.hidden = true;
|
|
533
|
+
this.dom.className = '';
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
const cn = buildClassName(this.props, 'none');
|
|
537
|
+
this.dom.className = cn;
|
|
538
|
+
this.dom.hidden = false;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
if (this.affectSet.has('recreateChildren')) {
|
|
542
|
+
this.recreateChildren();
|
|
543
|
+
}
|
|
544
|
+
if (this.affectSet.has('affectsChildrenProps')) {
|
|
545
|
+
this.childrenColl?.forEach(c => c.render('affectsProps', 'affectsChildrenProps'));
|
|
546
|
+
}
|
|
547
|
+
if (this.affectSet.size > 0) {
|
|
548
|
+
this.didDomUpdate();
|
|
549
|
+
this.affectSet.clear();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
recreateChildren() {
|
|
553
|
+
const actualItemsHash = [];
|
|
554
|
+
const actualItems = this._itemsFn ? [...this._itemsFn()] : [];
|
|
555
|
+
const actualChildren = [];
|
|
556
|
+
let index = 0;
|
|
557
|
+
if (!this.childrenColl)
|
|
558
|
+
this.childrenColl = [];
|
|
559
|
+
while (index < actualItems.length) {
|
|
560
|
+
const actualItem = actualItems[index];
|
|
561
|
+
const actualItemHash = this._itemHashFn(actualItem);
|
|
562
|
+
const oldVN = this.childrenColl[index];
|
|
563
|
+
if (index < this._oldItemsHash.length) {
|
|
564
|
+
if (actualItemHash === this._oldItemsHash[index]) {
|
|
565
|
+
actualChildren.push(oldVN);
|
|
547
566
|
}
|
|
548
567
|
else {
|
|
549
568
|
const newVN = this._itemRenderer(actualItem, index);
|
|
550
|
-
|
|
569
|
+
oldVN.dom.replaceWith(newVN.dom);
|
|
570
|
+
oldVN.destroy();
|
|
551
571
|
actualChildren.push(newVN);
|
|
552
572
|
}
|
|
553
|
-
actualItemsHash.push(actualItemHash);
|
|
554
|
-
index++;
|
|
555
573
|
}
|
|
556
|
-
|
|
557
|
-
this.
|
|
574
|
+
else {
|
|
575
|
+
const newVN = this._itemRenderer(actualItem, index);
|
|
576
|
+
this.dom.appendChild(newVN.dom);
|
|
577
|
+
actualChildren.push(newVN);
|
|
558
578
|
}
|
|
559
|
-
|
|
560
|
-
|
|
579
|
+
actualItemsHash.push(actualItemHash);
|
|
580
|
+
index++;
|
|
581
|
+
}
|
|
582
|
+
if (index < this.childrenColl.length) {
|
|
583
|
+
this.childrenColl.slice(index).forEach(n => n.destroy());
|
|
561
584
|
}
|
|
585
|
+
this.childrenColl = actualChildren;
|
|
586
|
+
this._oldItemsHash = actualItemsHash;
|
|
562
587
|
}
|
|
563
588
|
}
|
|
564
589
|
export const vlist = () => {
|
|
@@ -108,8 +108,9 @@ export declare class List<T, P extends UIComponentProps> extends UIComponent<P>
|
|
|
108
108
|
itemRenderer(fn: (item: T, index: number) => AnyUIComponent): this;
|
|
109
109
|
private _itemHashFn;
|
|
110
110
|
itemHash(fn: (item: T) => any): this;
|
|
111
|
+
protected updateDom(): void;
|
|
111
112
|
private _oldItemsHash;
|
|
112
|
-
|
|
113
|
+
private recreateChildren;
|
|
113
114
|
}
|
|
114
115
|
export declare const vlist: <T>() => List<T, StackProps>;
|
|
115
116
|
export declare const hlist: <T>() => List<T, StackProps>;
|