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 {BaseObservableMap} from "./BaseObservableMap";
|
||||||
import {SubscriptionHandle} from "../BaseObservable";
|
import {SubscriptionHandle} from "../BaseObservable";
|
||||||
import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults";
|
import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers";
|
||||||
|
|
||||||
|
|
||||||
export class ApplyMap<K, V> extends BaseObservableMap<K, V> {
|
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>) {
|
constructor(source: BaseObservableMap<K, V>, apply?: Apply<K, V>) {
|
||||||
super(new BaseObservableMapDefaults<K, V>());
|
super(new BaseObservableMapTransformers<K, V>());
|
||||||
this._source = source;
|
this._source = source;
|
||||||
this._apply = apply;
|
this._apply = apply;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ import {JoinedMap} from "../map/JoinedMap";
|
|||||||
import {MappedMap} from "../map/MappedMap";
|
import {MappedMap} from "../map/MappedMap";
|
||||||
import {FilteredMap} from "../map/FilteredMap";
|
import {FilteredMap} from "../map/FilteredMap";
|
||||||
import {SortedMapList} from "../list/SortedMapList.js";
|
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> {
|
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>> {
|
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();
|
super();
|
||||||
this._defaults = defaults;
|
this._defaults = defaults;
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,26 @@ import {JoinedMap} from "./JoinedMap";
|
|||||||
import {SortedMapList} from "../list/SortedMapList.js";
|
import {SortedMapList} from "../list/SortedMapList.js";
|
||||||
|
|
||||||
|
|
||||||
// This class provides implementations of functions that are part of BaseObservableMap.
|
// This class provides implementations of functions that transform one BaseObservableMap
|
||||||
// It is kept as its own class in its own file in order to avoid a circular
|
// to another type of Map. It's methods are effectively default implementations of the
|
||||||
// dependency between the classes that extend BaseObservableMap which are
|
// methods by the same name on BaseObservableMap.
|
||||||
// instantiated here (i.e. `new JoinedMap()`).
|
//
|
||||||
export class BaseObservableMapDefaults<K, V> {
|
// 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> {
|
join(_this: BaseObservableMap<K, V>, ...otherMaps: Array<BaseObservableMap<K, V>>): JoinedMap<K, V> {
|
||||||
return new JoinedMap([_this].concat(otherMaps));
|
return new JoinedMap([_this].concat(otherMaps));
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import {BaseObservableMap} from "./BaseObservableMap";
|
import {BaseObservableMap} from "./BaseObservableMap";
|
||||||
import {SubscriptionHandle} from "../BaseObservable";
|
import {SubscriptionHandle} from "../BaseObservable";
|
||||||
import {BaseObservableMapDefaults, Filter} from "./BaseObservableMapDefaults";
|
import {BaseObservableMapTransformers, Filter} from "./BaseObservableMapTransformers";
|
||||||
|
|
||||||
|
|
||||||
export class FilteredMap<K, V> extends BaseObservableMap<K, V> {
|
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;
|
private _subscription?: SubscriptionHandle;
|
||||||
|
|
||||||
constructor(source: BaseObservableMap<K, V>, filter: Filter<K, V>) {
|
constructor(source: BaseObservableMap<K, V>, filter: Filter<K, V>) {
|
||||||
super(new BaseObservableMapDefaults<K, V>());
|
super(new BaseObservableMapTransformers<K, V>());
|
||||||
this._source = source;
|
this._source = source;
|
||||||
this._filter = filter;
|
this._filter = filter;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseObservableMap} from "./BaseObservableMap";
|
import {BaseObservableMap} from "./BaseObservableMap";
|
||||||
import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults";
|
import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers";
|
||||||
import {SubscriptionHandle} from "../BaseObservable";
|
import {SubscriptionHandle} from "../BaseObservable";
|
||||||
|
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ export class JoinedMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
private _subscriptions?: SourceSubscriptionHandler<K, V>[];
|
private _subscriptions?: SourceSubscriptionHandler<K, V>[];
|
||||||
|
|
||||||
constructor(sources: BaseObservableMap<K, V>[]) {
|
constructor(sources: BaseObservableMap<K, V>[]) {
|
||||||
super(new BaseObservableMapDefaults<K, V>());
|
super(new BaseObservableMapTransformers<K, V>());
|
||||||
this._sources = sources;
|
this._sources = sources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseObservableMap} from "./BaseObservableMap";
|
import {BaseObservableMap} from "./BaseObservableMap";
|
||||||
import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults";
|
import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers";
|
||||||
import {SubscriptionHandle} from "../BaseObservable";
|
import {SubscriptionHandle} from "../BaseObservable";
|
||||||
import {ILogItem, LabelOrValues} from "../../logging/types";
|
import {ILogItem, LabelOrValues} from "../../logging/types";
|
||||||
import {LogLevel} from "../../logging/LogFilter";
|
import {LogLevel} from "../../logging/LogFilter";
|
||||||
@ -27,7 +27,7 @@ export class LogMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
private _log: ILogItem;
|
private _log: ILogItem;
|
||||||
|
|
||||||
constructor(source: BaseObservableMap<K, V>, log: ILogItem) {
|
constructor(source: BaseObservableMap<K, V>, log: ILogItem) {
|
||||||
super(new BaseObservableMapDefaults<K, V>());
|
super(new BaseObservableMapTransformers<K, V>());
|
||||||
this._source = source;
|
this._source = source;
|
||||||
this._log = log;
|
this._log = log;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseObservableMap} from "./BaseObservableMap";
|
import {BaseObservableMap} from "./BaseObservableMap";
|
||||||
import {BaseObservableMapDefaults, Mapper, Updater} from "./BaseObservableMapDefaults";
|
import {BaseObservableMapTransformers, Mapper, Updater} from "./BaseObservableMapTransformers";
|
||||||
import {SubscriptionHandle} from "../BaseObservable";
|
import {SubscriptionHandle} from "../BaseObservable";
|
||||||
|
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ export class MappedMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
mapper: Mapper<V>,
|
mapper: Mapper<V>,
|
||||||
updater?: Updater<V>
|
updater?: Updater<V>
|
||||||
) {
|
) {
|
||||||
super(new BaseObservableMapDefaults<K, V>());
|
super(new BaseObservableMapTransformers<K, V>());
|
||||||
this._source = source;
|
this._source = source;
|
||||||
this._mapper = mapper;
|
this._mapper = mapper;
|
||||||
this._updater = updater;
|
this._updater = updater;
|
||||||
|
@ -15,14 +15,14 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {BaseObservableMap} from "./BaseObservableMap";
|
import {BaseObservableMap} from "./BaseObservableMap";
|
||||||
import {BaseObservableMapDefaults} from "./BaseObservableMapDefaults";
|
import {BaseObservableMapTransformers} from "./BaseObservableMapTransformers";
|
||||||
|
|
||||||
|
|
||||||
export class ObservableMap<K, V> extends BaseObservableMap<K, V> {
|
export class ObservableMap<K, V> extends BaseObservableMap<K, V> {
|
||||||
private readonly _values: Map<K, V>;
|
private readonly _values: Map<K, V>;
|
||||||
|
|
||||||
constructor(initialValues?: (readonly [K, V])[]) {
|
constructor(initialValues?: (readonly [K, V])[]) {
|
||||||
super(new BaseObservableMapDefaults<K, V>());
|
super(new BaseObservableMapTransformers<K, V>());
|
||||||
this._values = new Map(initialValues);
|
this._values = new Map(initialValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user