Update ListView and TimelineListView

This commit is contained in:
Danila Fedorin 2021-09-29 18:08:13 -07:00
parent 414280ada9
commit 64ba656043
2 changed files with 24 additions and 10 deletions

View file

@ -27,7 +27,7 @@ interface IOptions<T, V> {
parentProvidesUpdates?: boolean parentProvidesUpdates?: boolean
} }
type SubscriptionHandle = () => undefined; type SubscriptionHandle = () => void;
export class ListView<T, V extends IView> implements IView { export class ListView<T, V extends IView> implements IView {
@ -115,7 +115,8 @@ export class ListView<T, V extends IView> implements IView {
} }
private _unloadList() { private _unloadList() {
this._subscription = this._subscription!(); this._subscription!()
this._subscription = undefined;
for (let child of this._childInstances!) { for (let child of this._childInstances!) {
child.unmount(); child.unmount();
} }
@ -137,26 +138,34 @@ export class ListView<T, V extends IView> implements IView {
this._root!.appendChild(fragment); this._root!.appendChild(fragment);
} }
protected onAdd(idx: number, value: T) { onReset() {
for (const child of this._childInstances!) {
child.root()!.remove();
child.unmount();
}
this._childInstances!.length = 0;
}
onAdd(idx: number, value: T) {
const child = this._childCreator(value); const child = this._childCreator(value);
this._childInstances!.splice(idx, 0, child); this._childInstances!.splice(idx, 0, child);
insertAt(this._root!, idx, mountView(child, this._mountArgs)); insertAt(this._root!, idx, mountView(child, this._mountArgs));
} }
protected onRemove(idx: number, value: T) { onRemove(idx: number, value: T) {
const [child] = this._childInstances!.splice(idx, 1); const [child] = this._childInstances!.splice(idx, 1);
child.root()!.remove(); child.root()!.remove();
child.unmount(); child.unmount();
} }
protected onMove(fromIdx: number, toIdx: number, value: T) { onMove(fromIdx: number, toIdx: number, value: T) {
const [child] = this._childInstances!.splice(fromIdx, 1); const [child] = this._childInstances!.splice(fromIdx, 1);
this._childInstances!.splice(toIdx, 0, child); this._childInstances!.splice(toIdx, 0, child);
child.root()!.remove(); child.root()!.remove();
insertAt(this._root!, toIdx, child.root()! as Element); insertAt(this._root!, toIdx, child.root()! as Element);
} }
protected onUpdate(i: number, value: T, params: any) { onUpdate(i: number, value: T, params: any) {
if (this._childInstances) { if (this._childInstances) {
const instance = this._childInstances![i]; const instance = this._childInstances![i];
instance && instance.update(value, params); instance && instance.update(value, params);

View file

@ -211,7 +211,12 @@ class TilesListView extends ListView<SimpleTile, TileView> {
this.onChanged = onChanged; this.onChanged = onChanged;
} }
protected onUpdate(index: number, value: SimpleTile, param: any) { onReset() {
super.onReset();
this.onChanged();
}
onUpdate(index: number, value: SimpleTile, param: any) {
if (param === "shape") { if (param === "shape") {
const ExpectedClass = viewClassForEntry(value); const ExpectedClass = viewClassForEntry(value);
const child = this.getChildInstanceByIndex(index); const child = this.getChildInstanceByIndex(index);
@ -227,17 +232,17 @@ class TilesListView extends ListView<SimpleTile, TileView> {
this.onChanged(); this.onChanged();
} }
protected onAdd(idx: number, value: SimpleTile) { onAdd(idx: number, value: SimpleTile) {
super.onAdd(idx, value); super.onAdd(idx, value);
this.onChanged(); this.onChanged();
} }
protected onRemove(idx: number, value: SimpleTile) { onRemove(idx: number, value: SimpleTile) {
super.onRemove(idx, value); super.onRemove(idx, value);
this.onChanged(); this.onChanged();
} }
protected onMove(fromIdx: number, toIdx: number, value: SimpleTile) { onMove(fromIdx: number, toIdx: number, value: SimpleTile) {
super.onMove(fromIdx, toIdx, value); super.onMove(fromIdx, toIdx, value);
this.onChanged(); this.onChanged();
} }