diff --git a/src/observable/list/BaseMappedList.ts b/src/observable/list/BaseMappedList.ts index 0435a760..8646153e 100644 --- a/src/observable/list/BaseMappedList.ts +++ b/src/observable/list/BaseMappedList.ts @@ -45,8 +45,7 @@ export class BaseMappedList extends BaseObservableList { return this._mappedValues!.length; } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - [Symbol.iterator]() { + [Symbol.iterator](): IterableIterator { return this._mappedValues!.values(); } } diff --git a/src/observable/list/ConcatList.ts b/src/observable/list/ConcatList.ts index aaad5a6a..80accb81 100644 --- a/src/observable/list/ConcatList.ts +++ b/src/observable/list/ConcatList.ts @@ -86,13 +86,11 @@ export class ConcatList extends BaseObservableList implements IListObserve return len; } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - [Symbol.iterator]() { + [Symbol.iterator](): Iterator { let sourceListIdx = 0; let it = this._sourceLists[0][Symbol.iterator](); return { - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - next: () => { + next: (): IteratorResult => { let result = it.next(); while (result.done) { sourceListIdx += 1; diff --git a/src/observable/list/ObservableArray.ts b/src/observable/list/ObservableArray.ts index 662f715e..1b962e81 100644 --- a/src/observable/list/ObservableArray.ts +++ b/src/observable/list/ObservableArray.ts @@ -75,8 +75,7 @@ export class ObservableArray extends BaseObservableList { return this._items.length; } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - [Symbol.iterator]() { + [Symbol.iterator](): IterableIterator { return this._items.values(); } } diff --git a/src/observable/list/SortedArray.ts b/src/observable/list/SortedArray.ts index c956f7b8..e4723db1 100644 --- a/src/observable/list/SortedArray.ts +++ b/src/observable/list/SortedArray.ts @@ -112,40 +112,31 @@ export class SortedArray extends BaseObservableList { return this._items.length; } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - [Symbol.iterator]() { + [Symbol.iterator](): Iterator { return new Iterator(this); } } // iterator that works even if the current value is removed while iterating class Iterator { - private _sortedArray: SortedArray | null - private _current: T | null | undefined + private _sortedArray: SortedArray; + private _current: T | null | undefined; + private _consumed: boolean = false; constructor(sortedArray: SortedArray) { this._sortedArray = sortedArray; this._current = null; } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - next() { - if (this._sortedArray) { - 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; - } + next(): IteratorResult { + if (this._consumed) { + return {value: undefined, done: true}; } - if (!this._sortedArray) { - return {done: true}; + this._current = this._current? this._sortedArray._getNext(this._current): this._sortedArray.get(0); + if (!this._current) { + this._consumed = true; } + return { value: this._current, done: this._consumed } as IteratorResult; } } diff --git a/src/observable/map/ApplyMap.ts b/src/observable/map/ApplyMap.ts index a13cf757..0c4962c8 100644 --- a/src/observable/map/ApplyMap.ts +++ b/src/observable/map/ApplyMap.ts @@ -79,7 +79,9 @@ export class ApplyMap extends BaseObservableMap { onUnsubscribeLast(): void { super.onUnsubscribeLast(); - if (this._subscription) this._subscription = this._subscription(); + if (this._subscription) { + this._subscription = this._subscription(); + } } onReset(): void { @@ -89,8 +91,7 @@ export class ApplyMap extends BaseObservableMap { this.emitReset(); } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - [Symbol.iterator]() { + [Symbol.iterator](): Iterator<[K, V]> { return this._source[Symbol.iterator](); } diff --git a/src/observable/map/FilteredMap.ts b/src/observable/map/FilteredMap.ts index 1fd7d89a..c97bc48a 100644 --- a/src/observable/map/FilteredMap.ts +++ b/src/observable/map/FilteredMap.ts @@ -142,8 +142,7 @@ export class FilteredMap extends BaseObservableMap { this.emitReset(); } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - [Symbol.iterator]() { + [Symbol.iterator](): FilterIterator { return new FilterIterator(this._source, this._included); } @@ -157,7 +156,7 @@ export class FilteredMap extends BaseObservableMap { return count; } - get(key): V | undefined{ + get(key: K): V | undefined { const value = this._source.get(key); if (value && this._filter(value, key)) { return value; @@ -173,8 +172,7 @@ class FilterIterator { this._sourceIterator = map[Symbol.iterator](); } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - next() { + next(): IteratorResult<[K, V]> { // eslint-disable-next-line no-constant-condition while (true) { const sourceResult = this._sourceIterator.next(); diff --git a/src/observable/map/LogMap.ts b/src/observable/map/LogMap.ts index 60ac7721..ce9d343e 100644 --- a/src/observable/map/LogMap.ts +++ b/src/observable/map/LogMap.ts @@ -72,8 +72,7 @@ export class LogMap extends BaseObservableMap { this.emitReset(); } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - [Symbol.iterator]() { + [Symbol.iterator](): Iterator<[K, V]> { return this._source[Symbol.iterator](); } diff --git a/src/observable/map/MappedMap.ts b/src/observable/map/MappedMap.ts index 0d2c47c0..6ada079f 100644 --- a/src/observable/map/MappedMap.ts +++ b/src/observable/map/MappedMap.ts @@ -64,7 +64,9 @@ export class MappedMap extends BaseObservableMap { onRemove(key: K/*, _value*/): void { const mappedValue = this._mappedValues.get(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 extends BaseObservableMap { onUnsubscribeLast(): void { super.onUnsubscribeLast(); - if (this._subscription) this._subscription = this._subscription(); + if (this._subscription) { + this._subscription = this._subscription(); + } this._mappedValues.clear(); } @@ -102,8 +106,7 @@ export class MappedMap extends BaseObservableMap { this.emitReset(); } - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - [Symbol.iterator]() { + [Symbol.iterator](): IterableIterator<[K, MappedV]> { return this._mappedValues.entries(); } diff --git a/src/observable/map/ObservableMap.ts b/src/observable/map/ObservableMap.ts index c5ffe397..f0d4c77a 100644 --- a/src/observable/map/ObservableMap.ts +++ b/src/observable/map/ObservableMap.ts @@ -97,7 +97,7 @@ export class ObservableMap extends BaseObservableMap { keys(): Iterator { return this._values.keys(); } -}; +} // eslint-disable-next-line @typescript-eslint/explicit-function-return-type export function tests() {