Relax types on BaseObservableList and add helper for tests

This commit is contained in:
Danila Fedorin 2021-09-29 19:25:47 -07:00
parent ddca467e30
commit 588da9b719

View file

@ -24,6 +24,17 @@ export interface IListObserver<T> {
onMove(from: number, to: number, value: T, list: BaseObservableList<T>): void onMove(from: number, to: number, value: T, list: BaseObservableList<T>): void
} }
export function defaultObserverWith<T>(overrides: { [key in keyof IListObserver<T>]?: IListObserver<T>[key] }): IListObserver<T> {
const defaults = {
onReset(){},
onAdd(){},
onUpdate(){},
onRemove(){},
onMove(){},
}
return Object.assign(defaults, overrides);
}
export abstract class BaseObservableList<T> extends BaseObservable<IListObserver<T>> { export abstract class BaseObservableList<T> extends BaseObservable<IListObserver<T>> {
emitReset() { emitReset() {
for(let h of this._handlers) { for(let h of this._handlers) {
@ -38,7 +49,7 @@ export abstract class BaseObservableList<T> extends BaseObservable<IListObserver
} }
} }
emitUpdate(index: number, value: T, params: any): void { emitUpdate(index: number, value: T, params?: any): void {
for(let h of this._handlers) { for(let h of this._handlers) {
h.onUpdate(index, value, params, this); h.onUpdate(index, value, params, this);
} }
@ -58,6 +69,6 @@ export abstract class BaseObservableList<T> extends BaseObservable<IListObserver
} }
} }
abstract [Symbol.iterator](): IterableIterator<T>; abstract [Symbol.iterator]();
abstract get length(): number; abstract get length(): number;
} }