mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 19:45:05 +01:00
Add type annotations to BaseObservableList
This commit is contained in:
parent
3952c3b969
commit
414280ada9
@ -16,7 +16,15 @@ limitations under the License.
|
|||||||
|
|
||||||
import {BaseObservable} from "../BaseObservable";
|
import {BaseObservable} from "../BaseObservable";
|
||||||
|
|
||||||
export class BaseObservableList extends BaseObservable {
|
export interface IListObserver<T> {
|
||||||
|
onReset(list: BaseObservableList<T>): void;
|
||||||
|
onAdd(index: number, value:T, list: BaseObservableList<T>): void;
|
||||||
|
onUpdate(index: number, value: T, params: any, list: BaseObservableList<T>): void;
|
||||||
|
onRemove(index: number, value: T, list: BaseObservableList<T>): void
|
||||||
|
onMove(from: number, to: number, value: T, list: BaseObservableList<T>): void
|
||||||
|
}
|
||||||
|
|
||||||
|
export abstract class BaseObservableList<T> extends BaseObservable<IListObserver<T>> {
|
||||||
emitReset() {
|
emitReset() {
|
||||||
for(let h of this._handlers) {
|
for(let h of this._handlers) {
|
||||||
h.onReset(this);
|
h.onReset(this);
|
||||||
@ -24,19 +32,19 @@ export class BaseObservableList extends BaseObservable {
|
|||||||
}
|
}
|
||||||
// we need batch events, mostly on index based collection though?
|
// we need batch events, mostly on index based collection though?
|
||||||
// maybe we should get started without?
|
// maybe we should get started without?
|
||||||
emitAdd(index, value) {
|
emitAdd(index: number, value: T): void {
|
||||||
for(let h of this._handlers) {
|
for(let h of this._handlers) {
|
||||||
h.onAdd(index, value, this);
|
h.onAdd(index, value, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emitUpdate(index, value, params) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emitRemove(index, value) {
|
emitRemove(index: number, value: T): void {
|
||||||
for(let h of this._handlers) {
|
for(let h of this._handlers) {
|
||||||
h.onRemove(index, value, this);
|
h.onRemove(index, value, this);
|
||||||
}
|
}
|
||||||
@ -44,17 +52,12 @@ export class BaseObservableList extends BaseObservable {
|
|||||||
|
|
||||||
// toIdx assumes the item has already
|
// toIdx assumes the item has already
|
||||||
// been removed from its fromIdx
|
// been removed from its fromIdx
|
||||||
emitMove(fromIdx, toIdx, value) {
|
emitMove(fromIdx: number, toIdx: number, value: T): void {
|
||||||
for(let h of this._handlers) {
|
for(let h of this._handlers) {
|
||||||
h.onMove(fromIdx, toIdx, value, this);
|
h.onMove(fromIdx, toIdx, value, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Symbol.iterator]() {
|
abstract [Symbol.iterator](): IterableIterator<T>;
|
||||||
throw new Error("unimplemented");
|
abstract get length(): number;
|
||||||
}
|
|
||||||
|
|
||||||
get length() {
|
|
||||||
throw new Error("unimplemented");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user