mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
src/observable/map/BaseObservableMapDefaults.ts -> src/observable/map/BaseObservableMapTransformers.ts
This commit is contained in:
parent
70b68c5b16
commit
dd01e70b4a
@ -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<K, V> extends BaseObservableMap<K, V> {
|
||||
@ -26,7 +26,7 @@ export class ApplyMap<K, V> extends BaseObservableMap<K, V> {
|
||||
|
||||
|
||||
constructor(source: BaseObservableMap<K, V>, apply?: Apply<K, V>) {
|
||||
super(new BaseObservableMapDefaults<K, V>());
|
||||
super(new BaseObservableMapTransformers<K, V>());
|
||||
this._source = source;
|
||||
this._apply = apply;
|
||||
}
|
||||
|
@ -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<K, V> {
|
||||
@ -30,9 +30,9 @@ export interface IMapObserver<K, V> {
|
||||
}
|
||||
|
||||
export abstract class BaseObservableMap<K, V> extends BaseObservable<IMapObserver<K, V>> {
|
||||
private _defaults: BaseObservableMapDefaults<K, V>;
|
||||
private _defaults: BaseObservableMapTransformers<K, V>;
|
||||
|
||||
constructor(defaults: BaseObservableMapDefaults<K, V>) {
|
||||
constructor(defaults: BaseObservableMapTransformers<K, V>) {
|
||||
super();
|
||||
this._defaults = defaults;
|
||||
}
|
||||
|
@ -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<K, V> {
|
||||
// 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<K, V> extends BaseObservable<IMapObserver<K, V>> {
|
||||
// join(...otherMaps: Array<BaseObservableMap<K, V>>): JoinedMap<K, V> {
|
||||
// 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<K, V> extends BaseObservableMap<K, V>`.
|
||||
export class BaseObservableMapTransformers<K, V> {
|
||||
join(_this: BaseObservableMap<K, V>, ...otherMaps: Array<BaseObservableMap<K, V>>): JoinedMap<K, V> {
|
||||
return new JoinedMap([_this].concat(otherMaps));
|
||||
}
|
@ -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<K, V> extends BaseObservableMap<K, V> {
|
||||
@ -26,7 +26,7 @@ export class FilteredMap<K, V> extends BaseObservableMap<K, V> {
|
||||
private _subscription?: SubscriptionHandle;
|
||||
|
||||
constructor(source: BaseObservableMap<K, V>, filter: Filter<K, V>) {
|
||||
super(new BaseObservableMapDefaults<K, V>());
|
||||
super(new BaseObservableMapTransformers<K, V>());
|
||||
this._source = source;
|
||||
this._filter = filter;
|
||||
}
|
||||
|
@ -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<K, V> extends BaseObservableMap<K, V> {
|
||||
private _subscriptions?: SourceSubscriptionHandler<K, V>[];
|
||||
|
||||
constructor(sources: BaseObservableMap<K, V>[]) {
|
||||
super(new BaseObservableMapDefaults<K, V>());
|
||||
super(new BaseObservableMapTransformers<K, V>());
|
||||
this._sources = sources;
|
||||
}
|
||||
|
||||
|
@ -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<K, V> extends BaseObservableMap<K, V> {
|
||||
private _log: ILogItem;
|
||||
|
||||
constructor(source: BaseObservableMap<K, V>, log: ILogItem) {
|
||||
super(new BaseObservableMapDefaults<K, V>());
|
||||
super(new BaseObservableMapTransformers<K, V>());
|
||||
this._source = source;
|
||||
this._log = log;
|
||||
}
|
||||
|
@ -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<K, V> extends BaseObservableMap<K, V> {
|
||||
mapper: Mapper<V>,
|
||||
updater?: Updater<V>
|
||||
) {
|
||||
super(new BaseObservableMapDefaults<K, V>());
|
||||
super(new BaseObservableMapTransformers<K, V>());
|
||||
this._source = source;
|
||||
this._mapper = mapper;
|
||||
this._updater = updater;
|
||||
|
@ -15,14 +15,14 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
import {BaseObservableMap} from "./BaseObservableMap";
|
||||
import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults";
|
||||
import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers";
|
||||
|
||||
|
||||
export class ObservableMap<K, V> extends BaseObservableMap<K, V> {
|
||||
private readonly _values: Map<K, V>;
|
||||
|
||||
constructor(initialValues?: (readonly [K, V])[]) {
|
||||
super(new BaseObservableMapDefaults<K, V>());
|
||||
super(new BaseObservableMapTransformers<K, V>());
|
||||
this._values = new Map(initialValues);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user