mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
fixes [Symbol.iterator] typing
This commit is contained in:
parent
1e6d5ca42f
commit
d025c1111e
@ -45,8 +45,7 @@ export class BaseMappedList<F,T,R = T> extends BaseObservableList<T> {
|
|||||||
return this._mappedValues!.length;
|
return this._mappedValues!.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
[Symbol.iterator](): IterableIterator<T> {
|
||||||
[Symbol.iterator]() {
|
|
||||||
return this._mappedValues!.values();
|
return this._mappedValues!.values();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,13 +86,11 @@ export class ConcatList<T> extends BaseObservableList<T> implements IListObserve
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
[Symbol.iterator](): Iterator<T> {
|
||||||
[Symbol.iterator]() {
|
|
||||||
let sourceListIdx = 0;
|
let sourceListIdx = 0;
|
||||||
let it = this._sourceLists[0][Symbol.iterator]();
|
let it = this._sourceLists[0][Symbol.iterator]();
|
||||||
return {
|
return {
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
next: (): IteratorResult<T> => {
|
||||||
next: () => {
|
|
||||||
let result = it.next();
|
let result = it.next();
|
||||||
while (result.done) {
|
while (result.done) {
|
||||||
sourceListIdx += 1;
|
sourceListIdx += 1;
|
||||||
|
@ -75,8 +75,7 @@ export class ObservableArray<T> extends BaseObservableList<T> {
|
|||||||
return this._items.length;
|
return this._items.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
[Symbol.iterator](): IterableIterator<T> {
|
||||||
[Symbol.iterator]() {
|
|
||||||
return this._items.values();
|
return this._items.values();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,40 +112,31 @@ export class SortedArray<T> extends BaseObservableList<T> {
|
|||||||
return this._items.length;
|
return this._items.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
[Symbol.iterator](): Iterator<T> {
|
||||||
[Symbol.iterator]() {
|
|
||||||
return new Iterator(this);
|
return new Iterator(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterator that works even if the current value is removed while iterating
|
// iterator that works even if the current value is removed while iterating
|
||||||
class Iterator<T> {
|
class Iterator<T> {
|
||||||
private _sortedArray: SortedArray<T> | null
|
private _sortedArray: SortedArray<T>;
|
||||||
private _current: T | null | undefined
|
private _current: T | null | undefined;
|
||||||
|
private _consumed: boolean = false;
|
||||||
|
|
||||||
constructor(sortedArray: SortedArray<T>) {
|
constructor(sortedArray: SortedArray<T>) {
|
||||||
this._sortedArray = sortedArray;
|
this._sortedArray = sortedArray;
|
||||||
this._current = null;
|
this._current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
next(): IteratorResult<T> {
|
||||||
next() {
|
if (this._consumed) {
|
||||||
if (this._sortedArray) {
|
return {value: undefined, done: true};
|
||||||
if (this._current) {
|
|
||||||
this._current = this._sortedArray._getNext(this._current);
|
|
||||||
} else {
|
|
||||||
this._current = this._sortedArray.get(0);
|
|
||||||
}
|
|
||||||
if (this._current) {
|
|
||||||
return {value: this._current};
|
|
||||||
} else {
|
|
||||||
// cause done below
|
|
||||||
this._sortedArray = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (!this._sortedArray) {
|
this._current = this._current? this._sortedArray._getNext(this._current): this._sortedArray.get(0);
|
||||||
return {done: true};
|
if (!this._current) {
|
||||||
|
this._consumed = true;
|
||||||
}
|
}
|
||||||
|
return { value: this._current, done: this._consumed } as IteratorResult<T>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,9 @@ export class ApplyMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
|
|
||||||
onUnsubscribeLast(): void {
|
onUnsubscribeLast(): void {
|
||||||
super.onUnsubscribeLast();
|
super.onUnsubscribeLast();
|
||||||
if (this._subscription) this._subscription = this._subscription();
|
if (this._subscription) {
|
||||||
|
this._subscription = this._subscription();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onReset(): void {
|
onReset(): void {
|
||||||
@ -89,8 +91,7 @@ export class ApplyMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
this.emitReset();
|
this.emitReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
[Symbol.iterator](): Iterator<[K, V]> {
|
||||||
[Symbol.iterator]() {
|
|
||||||
return this._source[Symbol.iterator]();
|
return this._source[Symbol.iterator]();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,8 +142,7 @@ export class FilteredMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
this.emitReset();
|
this.emitReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
[Symbol.iterator](): FilterIterator<K, V> {
|
||||||
[Symbol.iterator]() {
|
|
||||||
return new FilterIterator<K, V>(this._source, this._included);
|
return new FilterIterator<K, V>(this._source, this._included);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +156,7 @@ export class FilteredMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
get(key): V | undefined{
|
get(key: K): V | undefined {
|
||||||
const value = this._source.get(key);
|
const value = this._source.get(key);
|
||||||
if (value && this._filter(value, key)) {
|
if (value && this._filter(value, key)) {
|
||||||
return value;
|
return value;
|
||||||
@ -173,8 +172,7 @@ class FilterIterator<K, V> {
|
|||||||
this._sourceIterator = map[Symbol.iterator]();
|
this._sourceIterator = map[Symbol.iterator]();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
next(): IteratorResult<[K, V]> {
|
||||||
next() {
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (true) {
|
while (true) {
|
||||||
const sourceResult = this._sourceIterator.next();
|
const sourceResult = this._sourceIterator.next();
|
||||||
|
@ -72,8 +72,7 @@ export class LogMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
this.emitReset();
|
this.emitReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
[Symbol.iterator](): Iterator<[K, V]> {
|
||||||
[Symbol.iterator]() {
|
|
||||||
return this._source[Symbol.iterator]();
|
return this._source[Symbol.iterator]();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,9 @@ export class MappedMap<K, V, MappedV> extends BaseObservableMap<K, MappedV> {
|
|||||||
onRemove(key: K/*, _value*/): void {
|
onRemove(key: K/*, _value*/): void {
|
||||||
const mappedValue = this._mappedValues.get(key);
|
const mappedValue = this._mappedValues.get(key);
|
||||||
if (this._mappedValues.delete(key)) {
|
if (this._mappedValues.delete(key)) {
|
||||||
if (mappedValue) this.emitRemove(key, mappedValue);
|
if (mappedValue) {
|
||||||
|
this.emitRemove(key, mappedValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +95,9 @@ export class MappedMap<K, V, MappedV> extends BaseObservableMap<K, MappedV> {
|
|||||||
|
|
||||||
onUnsubscribeLast(): void {
|
onUnsubscribeLast(): void {
|
||||||
super.onUnsubscribeLast();
|
super.onUnsubscribeLast();
|
||||||
if (this._subscription) this._subscription = this._subscription();
|
if (this._subscription) {
|
||||||
|
this._subscription = this._subscription();
|
||||||
|
}
|
||||||
this._mappedValues.clear();
|
this._mappedValues.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,8 +106,7 @@ export class MappedMap<K, V, MappedV> extends BaseObservableMap<K, MappedV> {
|
|||||||
this.emitReset();
|
this.emitReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
[Symbol.iterator](): IterableIterator<[K, MappedV]> {
|
||||||
[Symbol.iterator]() {
|
|
||||||
return this._mappedValues.entries();
|
return this._mappedValues.entries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ export class ObservableMap<K, V> extends BaseObservableMap<K, V> {
|
|||||||
keys(): Iterator<K> {
|
keys(): Iterator<K> {
|
||||||
return this._values.keys();
|
return this._values.keys();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||||
export function tests() {
|
export function tests() {
|
||||||
|
Loading…
Reference in New Issue
Block a user