mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
Updates comparator
This commit is contained in:
parent
ab6a8ad3aa
commit
081cc05fa6
@ -31,7 +31,7 @@ export function defaultObserverWith<T>(overrides: { [key in keyof IListObserver<
|
|||||||
onUpdate(){},
|
onUpdate(){},
|
||||||
onRemove(){},
|
onRemove(){},
|
||||||
onMove(){},
|
onMove(){},
|
||||||
}
|
};
|
||||||
return Object.assign(defaults, overrides);
|
return Object.assign(defaults, overrides);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ export class SortedArray<T> extends BaseObservableList<T> {
|
|||||||
const idx = sortedIndex(this._items, item, this._comparator);
|
const idx = sortedIndex(this._items, item, this._comparator);
|
||||||
if (idx >= this._items.length || this._comparator(this._items[idx], item) !== 0) {
|
if (idx >= this._items.length || this._comparator(this._items[idx], item) !== 0) {
|
||||||
this._items.splice(idx, 0, item);
|
this._items.splice(idx, 0, item);
|
||||||
this.emitAdd(idx, item)
|
this.emitAdd(idx, item);
|
||||||
} else {
|
} else {
|
||||||
this._items[idx] = item;
|
this._items[idx] = item;
|
||||||
this.emitUpdate(idx, item, updateParams);
|
this.emitUpdate(idx, item, updateParams);
|
||||||
@ -183,5 +183,5 @@ export function tests() {
|
|||||||
// check done persists
|
// check done persists
|
||||||
assert.equal(it.next().done, true);
|
assert.equal(it.next().done, true);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ export class SortedMapList extends BaseObservableList {
|
|||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,5 +267,5 @@ export function tests() {
|
|||||||
assert.equal(updateFired, 1);
|
assert.equal(updateFired, 1);
|
||||||
assert.deepEqual(Array.from(list).map(v => v.number), [1, 3, 11]);
|
assert.deepEqual(Array.from(list).map(v => v.number), [1, 3, 11]);
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ export class ApplyMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
return this._config.mapValues(this, mapper, updater);
|
return this._config.mapValues(this, mapper, updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortValues(comparator?: (a: any, b: any) => number): SortedMapList {
|
sortValues(comparator: (a: V, b: V) => number): SortedMapList {
|
||||||
return this._config.sortValues(this, comparator);
|
return this._config.sortValues(this, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ export interface IMapObserver<K, V> {
|
|||||||
export type BaseObservableMapConfig<K, V> = {
|
export type BaseObservableMapConfig<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>;
|
||||||
mapValues(_this: BaseObservableMap<K, V>, mapper: any, updater?: (params: any) => void): MappedMap<K, V>;
|
mapValues(_this: BaseObservableMap<K, V>, mapper: any, updater?: (params: any) => void): MappedMap<K, V>;
|
||||||
sortValues(_this: BaseObservableMap<K, V>, comparator?: (a: any, b: any) => number): SortedMapList;
|
sortValues(_this: BaseObservableMap<K, V>, comparator: (a: V, b: V) => number): SortedMapList;
|
||||||
filterValues(_this: BaseObservableMap<K, V>, filter: (v: V, k: K) => boolean): FilteredMap<K, V>;
|
filterValues(_this: BaseObservableMap<K, V>, filter: (v: V, k: K) => boolean): FilteredMap<K, V>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ export abstract class BaseObservableMap<K, V> extends BaseObservable<IMapObserve
|
|||||||
// this one (which is most likely what you want to do).
|
// this one (which is most likely what you want to do).
|
||||||
abstract join(...otherMaps: Array<typeof this>): JoinedMap<K, V>;
|
abstract join(...otherMaps: Array<typeof this>): JoinedMap<K, V>;
|
||||||
abstract mapValues(mapper: any, updater?: (params: any) => void): MappedMap<K, V>;
|
abstract mapValues(mapper: any, updater?: (params: any) => void): MappedMap<K, V>;
|
||||||
abstract sortValues(comparator?: (a: any, b: any) => number): SortedMapList;
|
abstract sortValues(comparator: (a: V, b: V) => number): SortedMapList;
|
||||||
abstract filterValues(filter: (v: V, k: K) => boolean): FilteredMap<K, V>;
|
abstract filterValues(filter: (v: V, k: K) => boolean): FilteredMap<K, V>;
|
||||||
|
|
||||||
abstract [Symbol.iterator](): Iterator<[K, V]>;
|
abstract [Symbol.iterator](): Iterator<[K, V]>;
|
||||||
|
@ -43,7 +43,7 @@ export class FilteredMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
return this._config.mapValues(this, mapper, updater);
|
return this._config.mapValues(this, mapper, updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortValues(comparator?: (a: any, b: any) => number): SortedMapList {
|
sortValues(comparator: (a: V, b: V) => number): SortedMapList {
|
||||||
return this._config.sortValues(this, comparator);
|
return this._config.sortValues(this, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ export class JoinedMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
return this._config.mapValues(this, mapper, updater);
|
return this._config.mapValues(this, mapper, updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortValues(comparator?: (a: any, b: any) => number): SortedMapList {
|
sortValues(comparator: (a: V, b: V) => number): SortedMapList {
|
||||||
return this._config.sortValues(this, comparator);
|
return this._config.sortValues(this, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import {FilteredMap} from "./FilteredMap.js";
|
|||||||
import {MappedMap} from "./MappedMap.js";
|
import {MappedMap} from "./MappedMap.js";
|
||||||
import {JoinedMap} from "./JoinedMap.js";
|
import {JoinedMap} from "./JoinedMap.js";
|
||||||
import {SortedMapList} from "../list/SortedMapList.js";
|
import {SortedMapList} from "../list/SortedMapList.js";
|
||||||
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";
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ export class LogMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
return this._config.mapValues(this, mapper, updater);
|
return this._config.mapValues(this, mapper, updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortValues(comparator?: (a: any, b: any) => number): SortedMapList {
|
sortValues(comparator: (a: V, b: V) => number): SortedMapList {
|
||||||
return this._config.sortValues(this, comparator);
|
return this._config.sortValues(this, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ export class MappedMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
return this._config.mapValues(this, mapper, updater);
|
return this._config.mapValues(this, mapper, updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortValues(comparator?: (a: any, b: any) => number): SortedMapList {
|
sortValues(comparator: (a: V, b: V) => number): SortedMapList {
|
||||||
return this._config.sortValues(this, comparator);
|
return this._config.sortValues(this, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ export class ObservableMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
return this._config.mapValues(this, mapper, updater);
|
return this._config.mapValues(this, mapper, updater);
|
||||||
}
|
}
|
||||||
|
|
||||||
sortValues(comparator?: (a: any, b: any) => number): SortedMapList {
|
sortValues(comparator: (a: V, b: V) => number): SortedMapList {
|
||||||
return this._config.sortValues(this, comparator);
|
return this._config.sortValues(this, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,5 +249,5 @@ export function tests() {
|
|||||||
map.add(2, {number: 6});
|
map.add(2, {number: 6});
|
||||||
assert.equal(map.size, 2);
|
assert.equal(map.size, 2);
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ export function config<K, V>(): BaseObservableMapConfig<K, V> {
|
|||||||
mapValues: (_this: BaseObservableMap<K, V>, mapper: any, updater: (params: any) => void): MappedMap<K, V> => {
|
mapValues: (_this: BaseObservableMap<K, V>, mapper: any, updater: (params: any) => void): MappedMap<K, V> => {
|
||||||
return new MappedMap(_this, mapper, updater);
|
return new MappedMap(_this, mapper, updater);
|
||||||
},
|
},
|
||||||
sortValues: (_this: BaseObservableMap<K, V>, comparator?: (a: any, b: any) => number): SortedMapList => {
|
sortValues: (_this: BaseObservableMap<K, V>, comparator: (a: V, b: V) => number): SortedMapList => {
|
||||||
return new SortedMapList(_this, comparator);
|
return new SortedMapList(_this, comparator);
|
||||||
},
|
},
|
||||||
filterValues: (_this: BaseObservableMap<K, V>, filter: (v: V, k: K) => boolean): FilteredMap<K, V> => {
|
filterValues: (_this: BaseObservableMap<K, V>, filter: (v: V, k: K) => boolean): FilteredMap<K, V> => {
|
||||||
|
Loading…
Reference in New Issue
Block a user