refactor(ivy): avoid circular dep with query/di/instructions (#21430)
To prepare for pending ngForOf work, the dep from instructions -> query should be broken. This will enable a dep from di -> instructions while avoiding a di -> instructions -> query -> di cycle. Analyzing this cycle also uncovered another problem: the implementation of query() breaks tree-shaking through a hard dependency on DI concepts of TemplateRef, ElementRef, ViewContainerRef. This is fundamentally due to how query() can query for those values without any configuration. Instead, this fix introduces the concept by employing the strategy pattern, and redefining QueryReadType to pass a function which will return one of the above values. This strategy is then used for 'read' instead of an enum in cases where special values should be read from the DI system. PR Close #21430
This commit is contained in:

committed by
Miško Hevery

parent
c5586b7dfa
commit
6472661ae8
@ -9,6 +9,7 @@
|
||||
import {QueryList} from '../../linker';
|
||||
import {Type} from '../../type';
|
||||
|
||||
import {LInjector} from './injector';
|
||||
import {LContainerNode, LNode, LViewNode} from './node';
|
||||
|
||||
|
||||
@ -48,15 +49,10 @@ export interface LQuery {
|
||||
*/
|
||||
track<T>(
|
||||
queryList: QueryList<T>, predicate: Type<any>|string[], descend?: boolean,
|
||||
read?: QueryReadType|Type<T>): void;
|
||||
read?: QueryReadType<T>|Type<T>): void;
|
||||
}
|
||||
|
||||
/** An enum representing possible values of the "read" option for queries. */
|
||||
export const enum QueryReadType {
|
||||
ElementRef = 0,
|
||||
ViewContainerRef = 1,
|
||||
TemplateRef = 2,
|
||||
}
|
||||
export class QueryReadType<T> { private defeatStructuralTyping: any; }
|
||||
|
||||
// Note: This hack is necessary so we don't erroneously get a circular dependency
|
||||
// failure based on types.
|
||||
|
Reference in New Issue
Block a user