refactor(ivy): remove duplicated flatten util (#29547)
This commit removes code duplication where we had 2 versions of a `flatten` utility. Moreover this change results in queries using a non-recursive version of `flatten` which should result in a better performance of query refresh operations. PR Close #29547
This commit is contained in:

committed by
Miško Hevery

parent
401b8eedd5
commit
dd69e4e780
@ -9,6 +9,7 @@
|
||||
import {Observable} from 'rxjs';
|
||||
|
||||
import {EventEmitter} from '../event_emitter';
|
||||
import {flatten} from '../util/array_utils';
|
||||
import {getSymbolIterator} from '../util/symbol';
|
||||
|
||||
|
||||
@ -110,7 +111,7 @@ export class QueryList<T>/* implements Iterable<T> */ {
|
||||
* @param resultsTree The results tree to store
|
||||
*/
|
||||
reset(resultsTree: Array<T|any[]>): void {
|
||||
this._results = depthFirstFlatten(resultsTree);
|
||||
this._results = flatten(resultsTree);
|
||||
(this as{dirty: boolean}).dirty = false;
|
||||
(this as{length: number}).length = this._results.length;
|
||||
(this as{last: T}).last = this._results[this.length - 1];
|
||||
@ -131,10 +132,3 @@ export class QueryList<T>/* implements Iterable<T> */ {
|
||||
(this.changes as EventEmitter<any>).unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
function depthFirstFlatten<T>(list: Array<T|T[]>): T[] {
|
||||
return list.reduce((flat: any[], item: T | T[]): T[] => {
|
||||
const flatItem = Array.isArray(item) ? depthFirstFlatten(item) : item;
|
||||
return (<T[]>flat).concat(flatItem);
|
||||
}, []);
|
||||
}
|
||||
|
Reference in New Issue
Block a user