From edeec896ae6aa7d55a89d41400f35a62087a193a Mon Sep 17 00:00:00 2001 From: Isaiah Becker-Mayer Date: Fri, 8 Jul 2022 20:39:07 -0400 Subject: [PATCH] typescriptifies SourceSubscriptionHandler --- src/observable/map/JoinedMap.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/observable/map/JoinedMap.ts b/src/observable/map/JoinedMap.ts index 11589ba5..6f285fd9 100644 --- a/src/observable/map/JoinedMap.ts +++ b/src/observable/map/JoinedMap.ts @@ -19,12 +19,13 @@ import {config} from "./config"; import {FilteredMap} from "./FilteredMap.js"; import {MappedMap} from "./MappedMap.js"; import {SortedMapList} from "../list/SortedMapList.js"; +import {SubscriptionHandle} from "../BaseObservable" export class JoinedMap extends BaseObservableMap { protected _sources: BaseObservableMap[]; private _config: BaseObservableMapConfig - private _subscriptions?: SourceSubscriptionHandler[]; + private _subscriptions?: SourceSubscriptionHandler[]; constructor(sources: BaseObservableMap[]) { super(); @@ -186,11 +187,15 @@ class JoinedIterator implements Iterator<[K, V]> { } } -class SourceSubscriptionHandler { - constructor(source, joinedMap) { +class SourceSubscriptionHandler { + private _source: BaseObservableMap; + private _joinedMap: JoinedMap; + private _subscription?: SubscriptionHandle; + + constructor(source: BaseObservableMap, joinedMap: JoinedMap) { this._source = source; this._joinedMap = joinedMap; - this._subscription = null; + this._subscription = undefined; } subscribe() { @@ -199,23 +204,23 @@ class SourceSubscriptionHandler { } dispose() { - this._subscription = this._subscription(); + if (this._subscription) this._subscription = this._subscription(); } - onAdd(key, value) { + onAdd(key: K, value: V) { this._joinedMap.onAdd(this._source, key, value); } - onRemove(key, value) { + onRemove(key: K, value: V) { this._joinedMap.onRemove(this._source, key, value); } - onUpdate(key, value, params) { + onUpdate(key: K, value: V, params: any) { this._joinedMap.onUpdate(this._source, key, value, params); } onReset() { - this._joinedMap.onReset(this._source); + this._joinedMap.onReset(); } }