Skip to content

Commit

Permalink
Fixes MappedMap type system
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaiah Becker-Mayer committed Aug 19, 2022
1 parent dd01e70 commit 92ed503
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/observable/map/BaseObservableMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/observable/map/BaseObservableMapTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;

Expand Down
18 changes: 9 additions & 9 deletions src/observable/map/MappedMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 92ed503

Please sign in to comment.