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
}
type SubscriptionHandle = () => undefined;
type SubscriptionHandle = () => void;
export class ListView<T, V extends IView> implements IView {
@ -115,7 +115,8 @@ export class ListView<T, V extends IView> implements IView {
}
private _unloadList() {
this._subscription = this._subscription!();
this._subscription!()
this._subscription = undefined;
for (let child of this._childInstances!) {
child.unmount();
}
@ -137,26 +138,34 @@ export class ListView<T, V extends IView> implements IView {
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);
this._childInstances!.splice(idx, 0, child);
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);
child.root()!.remove();
child.unmount();
}
protected onMove(fromIdx: number, toIdx: number, value: T) {
onMove(fromIdx: number, toIdx: number, value: T) {
const [child] = this._childInstances!.splice(fromIdx, 1);
this._childInstances!.splice(toIdx, 0, child);
child.root()!.remove();
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) {
const instance = this._childInstances![i];
instance && instance.update(value, params);

View file

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