mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Fixes MappedMap type system
This commit is contained in:
parent
dd01e70b4a
commit
92ed503700
@ -66,7 +66,7 @@ export abstract class BaseObservableMap<K, V> extends BaseObservable<IMapObserve
|
||||
return this._defaults.join(this, ...otherMaps);
|
||||
}
|
||||
|
||||
mapValues(mapper: Mapper<V>, updater?: Updater<V>): MappedMap<K, V> {
|
||||
mapValues<MappedV>(mapper: Mapper<V, MappedV>, updater?: Updater<V, MappedV>): MappedMap<K, V, MappedV> {
|
||||
return this._defaults.mapValues(this, mapper, updater);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ export class BaseObservableMapTransformers<K, V> {
|
||||
return new JoinedMap([_this].concat(otherMaps));
|
||||
}
|
||||
|
||||
mapValues(_this: BaseObservableMap<K, V>, mapper: Mapper<V>, updater?: Updater<V>): MappedMap<K, V> {
|
||||
mapValues<MappedV>(_this: BaseObservableMap<K, V>, mapper: Mapper<V, MappedV>, updater?: Updater<V, MappedV>): MappedMap<K, V, MappedV> {
|
||||
return new MappedMap(_this, mapper, updater);
|
||||
}
|
||||
|
||||
@ -57,12 +57,12 @@ export class BaseObservableMapTransformers<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
export type Mapper<V> = (
|
||||
export type Mapper<V, MappedV> = (
|
||||
value: V,
|
||||
emitSpontaneousUpdate: any,
|
||||
) => V;
|
||||
) => MappedV;
|
||||
|
||||
export type Updater<V> = (params: any, mappedValue?: V, value?: V) => void;
|
||||
export type Updater<V, MappedV> = (params: any, mappedValue?: MappedV, value?: V) => void;
|
||||
|
||||
export type Comparator<V> = (a: V, b: V) => number;
|
||||
|
||||
|
@ -23,24 +23,24 @@ import {SubscriptionHandle} from "../BaseObservable";
|
||||
so a mapped value can emit updates on it's own with this._emitSpontaneousUpdate that is passed in the mapping function
|
||||
how should the mapped value be notified of an update though? and can it then decide to not propagate the update?
|
||||
*/
|
||||
export class MappedMap<K, V> extends BaseObservableMap<K, V> {
|
||||
export class MappedMap<K, V, MappedV> extends BaseObservableMap<K, MappedV> {
|
||||
private _source: BaseObservableMap<K, V>;
|
||||
private _mapper: Mapper<V>;
|
||||
private _updater?: Updater<V>;
|
||||
private _mappedValues: Map<K, V>;
|
||||
private _mapper: Mapper<V, MappedV>;
|
||||
private _updater?: Updater<V, MappedV>;
|
||||
private _mappedValues: Map<K, MappedV>;
|
||||
private _subscription?: SubscriptionHandle;
|
||||
|
||||
|
||||
constructor(
|
||||
source: BaseObservableMap<K, V>,
|
||||
mapper: Mapper<V>,
|
||||
updater?: Updater<V>
|
||||
mapper: Mapper<V, MappedV>,
|
||||
updater?: Updater<V, MappedV>
|
||||
) {
|
||||
super(new BaseObservableMapTransformers<K, V>());
|
||||
super(new BaseObservableMapTransformers<K, MappedV>());
|
||||
this._source = source;
|
||||
this._mapper = mapper;
|
||||
this._updater = updater;
|
||||
this._mappedValues = new Map<K, V>();
|
||||
this._mappedValues = new Map<K, MappedV>();
|
||||
}
|
||||
|
||||
_emitSpontaneousUpdate(key: K, params: any): void {
|
||||
@ -107,7 +107,7 @@ export class MappedMap<K, V> extends BaseObservableMap<K, V> {
|
||||
return this._mappedValues.size;
|
||||
}
|
||||
|
||||
get(key: K): V | undefined {
|
||||
get(key: K): MappedV | undefined {
|
||||
return this._mappedValues.get(key);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user