diff --git a/src/observable/map/ApplyMap.ts b/src/observable/map/ApplyMap.ts index 1786873a..ee40c797 100644 --- a/src/observable/map/ApplyMap.ts +++ b/src/observable/map/ApplyMap.ts @@ -16,7 +16,7 @@ limitations under the License. import {BaseObservableMap} from "./BaseObservableMap"; import {SubscriptionHandle} from "../BaseObservable"; -import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults"; +import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers"; export class ApplyMap extends BaseObservableMap { @@ -26,7 +26,7 @@ export class ApplyMap extends BaseObservableMap { constructor(source: BaseObservableMap, apply?: Apply) { - super(new BaseObservableMapDefaults()); + super(new BaseObservableMapTransformers()); this._source = source; this._apply = apply; } diff --git a/src/observable/map/BaseObservableMap.ts b/src/observable/map/BaseObservableMap.ts index 86300439..aa76f641 100644 --- a/src/observable/map/BaseObservableMap.ts +++ b/src/observable/map/BaseObservableMap.ts @@ -19,7 +19,7 @@ import {JoinedMap} from "../map/JoinedMap"; import {MappedMap} from "../map/MappedMap"; import {FilteredMap} from "../map/FilteredMap"; import {SortedMapList} from "../list/SortedMapList.js"; -import type {BaseObservableMapDefaults, Mapper, Updater, Comparator, Filter} from "./BaseObservableMapDefaults"; +import type {BaseObservableMapTransformers, Mapper, Updater, Comparator, Filter} from "./BaseObservableMapTransformers"; export interface IMapObserver { @@ -30,9 +30,9 @@ export interface IMapObserver { } export abstract class BaseObservableMap extends BaseObservable> { - private _defaults: BaseObservableMapDefaults; + private _defaults: BaseObservableMapTransformers; - constructor(defaults: BaseObservableMapDefaults) { + constructor(defaults: BaseObservableMapTransformers) { super(); this._defaults = defaults; } diff --git a/src/observable/map/BaseObservableMapDefaults.ts b/src/observable/map/BaseObservableMapTransformers.ts similarity index 63% rename from src/observable/map/BaseObservableMapDefaults.ts rename to src/observable/map/BaseObservableMapTransformers.ts index 444b8640..3b39587d 100644 --- a/src/observable/map/BaseObservableMapDefaults.ts +++ b/src/observable/map/BaseObservableMapTransformers.ts @@ -20,11 +20,26 @@ import {JoinedMap} from "./JoinedMap"; import {SortedMapList} from "../list/SortedMapList.js"; -// This class provides implementations of functions that are part of BaseObservableMap. -// It is kept as its own class in its own file in order to avoid a circular -// dependency between the classes that extend BaseObservableMap which are -// instantiated here (i.e. `new JoinedMap()`). -export class BaseObservableMapDefaults { +// This class provides implementations of functions that transform one BaseObservableMap +// to another type of Map. It's methods are effectively default implementations of the +// methods by the same name on BaseObservableMap. +// +// It is kept as its own class in its own file in order to avoid circular dependencies +// which would occur if these method implementations were defined on BaseObservableMap +// itself. For example, if we attmpted to do the following on BaseObservableMap: +// +// class BaseObservableMap extends BaseObservable> { +// join(...otherMaps: Array>): JoinedMap { +// return new JoinedMap(this.concat(otherMaps)); +// } +// } +// +// we would end up with a circular dependency between BaseObservableMap and JoinedMap, +// since BaseObservableMap would need to import JoinedMap for the +// `return new JoinedMap(this.concat(otherMaps))`, and +// JoinedMap would need to import BaseObservableMap to do +// `JoinedMap extends BaseObservableMap`. +export class BaseObservableMapTransformers { join(_this: BaseObservableMap, ...otherMaps: Array>): JoinedMap { return new JoinedMap([_this].concat(otherMaps)); } diff --git a/src/observable/map/FilteredMap.ts b/src/observable/map/FilteredMap.ts index 267d0d35..2f3ba9fd 100644 --- a/src/observable/map/FilteredMap.ts +++ b/src/observable/map/FilteredMap.ts @@ -16,7 +16,7 @@ limitations under the License. import {BaseObservableMap} from "./BaseObservableMap"; import {SubscriptionHandle} from "../BaseObservable"; -import {BaseObservableMapDefaults, Filter} from "./BaseObservableMapDefaults"; +import {BaseObservableMapTransformers, Filter} from "./BaseObservableMapTransformers"; export class FilteredMap extends BaseObservableMap { @@ -26,7 +26,7 @@ export class FilteredMap extends BaseObservableMap { private _subscription?: SubscriptionHandle; constructor(source: BaseObservableMap, filter: Filter) { - super(new BaseObservableMapDefaults()); + super(new BaseObservableMapTransformers()); this._source = source; this._filter = filter; } diff --git a/src/observable/map/JoinedMap.ts b/src/observable/map/JoinedMap.ts index b343d22f..f6cb074a 100644 --- a/src/observable/map/JoinedMap.ts +++ b/src/observable/map/JoinedMap.ts @@ -15,7 +15,7 @@ limitations under the License. */ import {BaseObservableMap} from "./BaseObservableMap"; -import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults"; +import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers"; import {SubscriptionHandle} from "../BaseObservable"; @@ -24,7 +24,7 @@ export class JoinedMap extends BaseObservableMap { private _subscriptions?: SourceSubscriptionHandler[]; constructor(sources: BaseObservableMap[]) { - super(new BaseObservableMapDefaults()); + super(new BaseObservableMapTransformers()); this._sources = sources; } diff --git a/src/observable/map/LogMap.ts b/src/observable/map/LogMap.ts index 6db70f01..15f204d2 100644 --- a/src/observable/map/LogMap.ts +++ b/src/observable/map/LogMap.ts @@ -15,7 +15,7 @@ limitations under the License. */ import {BaseObservableMap} from "./BaseObservableMap"; -import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults"; +import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers"; import {SubscriptionHandle} from "../BaseObservable"; import {ILogItem, LabelOrValues} from "../../logging/types"; import {LogLevel} from "../../logging/LogFilter"; @@ -27,7 +27,7 @@ export class LogMap extends BaseObservableMap { private _log: ILogItem; constructor(source: BaseObservableMap, log: ILogItem) { - super(new BaseObservableMapDefaults()); + super(new BaseObservableMapTransformers()); this._source = source; this._log = log; } diff --git a/src/observable/map/MappedMap.ts b/src/observable/map/MappedMap.ts index 72115d84..bd091856 100644 --- a/src/observable/map/MappedMap.ts +++ b/src/observable/map/MappedMap.ts @@ -15,7 +15,7 @@ limitations under the License. */ import {BaseObservableMap} from "./BaseObservableMap"; -import {BaseObservableMapDefaults, Mapper, Updater} from "./BaseObservableMapDefaults"; +import {BaseObservableMapTransformers, Mapper, Updater} from "./BaseObservableMapTransformers"; import {SubscriptionHandle} from "../BaseObservable"; @@ -36,7 +36,7 @@ export class MappedMap extends BaseObservableMap { mapper: Mapper, updater?: Updater ) { - super(new BaseObservableMapDefaults()); + super(new BaseObservableMapTransformers()); this._source = source; this._mapper = mapper; this._updater = updater; diff --git a/src/observable/map/ObservableMap.ts b/src/observable/map/ObservableMap.ts index 9527ffdd..09a73d71 100644 --- a/src/observable/map/ObservableMap.ts +++ b/src/observable/map/ObservableMap.ts @@ -15,14 +15,14 @@ limitations under the License. */ import {BaseObservableMap} from "./BaseObservableMap"; -import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults"; +import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers"; export class ObservableMap extends BaseObservableMap { private readonly _values: Map; constructor(initialValues?: (readonly [K, V])[]) { - super(new BaseObservableMapDefaults()); + super(new BaseObservableMapTransformers()); this._values = new Map(initialValues); }