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.
@@ -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
- didDomUpdate() {
525
- super.didDomUpdate();
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
- const actualItemsHash = [];
528
- const actualItems = this._itemsFn ? [...this._itemsFn()] : [];
529
- const actualChildren = [];
530
- let index = 0;
531
- if (!this.childrenColl)
532
- this.childrenColl = [];
533
- while (index < actualItems.length) {
534
- const actualItem = actualItems[index];
535
- const actualItemHash = this._itemHashFn(actualItem);
536
- const oldVN = this.childrenColl[index];
537
- if (index < this._oldItemsHash.length) {
538
- if (actualItemHash === this._oldItemsHash[index]) {
539
- actualChildren.push(oldVN);
540
- }
541
- else {
542
- const newVN = this._itemRenderer(actualItem, index);
543
- oldVN.dom.replaceWith(newVN.dom);
544
- oldVN.destroy();
545
- actualChildren.push(newVN);
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
- this.dom.appendChild(newVN.dom);
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
- if (index < this.childrenColl.length) {
557
- this.childrenColl.slice(index).forEach(n => n.destroy());
574
+ else {
575
+ const newVN = this._itemRenderer(actualItem, index);
576
+ this.dom.appendChild(newVN.dom);
577
+ actualChildren.push(newVN);
558
578
  }
559
- this.childrenColl = actualChildren;
560
- this._oldItemsHash = actualItemsHash;
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
- protected didDomUpdate(): void;
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>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "flinker-dom",
3
3
  "description": "Free TypeScript library for writing frontend apps",
4
- "version": "1.1.0",
4
+ "version": "1.1.2",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/Dittner/FlinkerDOM.git"