mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Relax types on BaseObservableList and add helper for tests
This commit is contained in:
parent
ddca467e30
commit
588da9b719
@ -24,6 +24,17 @@ export interface IListObserver<T> {
|
||||
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>> {
|
||||
emitReset() {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user