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);
|
||||
}, []);
|
||||
}
|
||||
|
@ -9,7 +9,9 @@
|
||||
import {SRCSET_ATTRS, URI_ATTRS, VALID_ATTRS, VALID_ELEMENTS, getTemplateContent} from '../sanitization/html_sanitizer';
|
||||
import {InertBodyHelper} from '../sanitization/inert_body';
|
||||
import {_sanitizeUrl, sanitizeSrcset} from '../sanitization/url_sanitizer';
|
||||
import {addAllToArray} from '../util/array_utils';
|
||||
import {assertDefined, assertEqual, assertGreaterThan} from '../util/assert';
|
||||
|
||||
import {attachPatchData} from './context_discovery';
|
||||
import {allocExpando, createNodeAtIndex, elementAttribute, load, textBinding} from './instructions/all';
|
||||
import {LContainer, NATIVE} from './interfaces/container';
|
||||
@ -22,7 +24,6 @@ import {BINDING_INDEX, HEADER_OFFSET, LView, RENDERER, TVIEW, TView, T_HOST} fro
|
||||
import {appendChild, createTextNode, nativeRemoveNode} from './node_manipulation';
|
||||
import {getIsParent, getLView, getPreviousOrParentTNode, setIsParent, setPreviousOrParentTNode} from './state';
|
||||
import {NO_CHANGE} from './tokens';
|
||||
import {addAllToArray} from './util/array_utils';
|
||||
import {renderStringify} from './util/misc_utils';
|
||||
import {getNativeByIndex, getNativeByTNode, getTNode, isLContainer} from './util/view_utils';
|
||||
|
||||
|
Reference in New Issue
Block a user