mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(core): tweak runtime deps tracker to accommodate JIT requirements. (#50606)
The previous API design for the runtime deps tracker was done with only local compilation in mind. Now if we want to use it for JIT as well then some new requirements come along which are addressed by this commit as follows: - JIT scopes need distinct sets for directive and pipes. Thus the ScopeData interface is modified to include these info. - JIT needs access to scopes for various operations. So methods `getNgModuleScope` and `getStandaloneComponentScope` are added to the tracker's public api. - Test bed needs to clear the scope cache for its override mechanism. So method `clearScopeCacheFor` is added to the tracker's public api for this reason. PR Close #50606
This commit is contained in:
committed by
Andrew Kushnir
parent
bff1010a6f
commit
7d7fc48e58
@@ -7,19 +7,26 @@
|
||||
*/
|
||||
|
||||
import {Type} from '../../core';
|
||||
import {NgModuleScopeInfoFromDecorator} from '../interfaces/definition';
|
||||
import {NgModuleType} from '../../metadata/ng_module_def';
|
||||
import {ComponentType, DependencyTypeList, DirectiveTypeList, NgModuleScopeInfoFromDecorator, PipeTypeList} from '../interfaces/definition';
|
||||
|
||||
/**
|
||||
* Represents the set of dependencies of a type in a certain context.
|
||||
*
|
||||
* The absence of dependencies field indicates that calculating this scope somehow was not
|
||||
* successful. Consumers should interpret this as empty dependencies. The reason for this error is
|
||||
* displayed as an error message in the console as per JIT behavior today. In addition to that, in
|
||||
* local compilation the other build/compilations run in parallel with local compilation may (or may
|
||||
* not) reveal some details about the error as well.
|
||||
*/
|
||||
interface ScopeData {
|
||||
dependencies?: Type<any>[];
|
||||
pipes: PipeTypeList;
|
||||
directives: DirectiveTypeList;
|
||||
|
||||
/**
|
||||
* If true it indicates that calculating this scope somehow was not successful. The consumers
|
||||
* should interpret this as empty dependencies. The application of this flag is when calculating
|
||||
* scope recursively, the presence of this flag in a scope dependency implies that the scope is
|
||||
* also poisoned and thus we can return immediately without having to continue the recursion. The
|
||||
* reason for this error is displayed as an error message in the console as per JIT behavior
|
||||
* today. In addition to that, in local compilation the other build/compilations run in parallel
|
||||
* with local compilation may or may not reveal some details about the error as well.
|
||||
*/
|
||||
isPoisoned?: boolean;
|
||||
}
|
||||
|
||||
/** Represents scope data for NgModule as calculated during runtime by the deps tracker. */
|
||||
@@ -37,7 +44,7 @@ export interface StandaloneComponentScope {
|
||||
|
||||
/** Component dependencies info as calculated during runtime by the deps tracker. */
|
||||
export interface ComponentDependencies {
|
||||
dependencies: Type<any>[];
|
||||
dependencies: DependencyTypeList;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,7 +61,7 @@ export interface DepsTrackerApi {
|
||||
* The implementation is expected to use some caching mechanism in order to optimize the resources
|
||||
* needed to do this computation.
|
||||
*/
|
||||
getComponentDependencies(cmp: Type<any>): ComponentDependencies;
|
||||
getComponentDependencies(cmp: ComponentType<any>): ComponentDependencies;
|
||||
|
||||
/**
|
||||
* Registers an NgModule into the tracker with the given scope info.
|
||||
@@ -64,4 +71,30 @@ export interface DepsTrackerApi {
|
||||
* different compilation units with different compilation mode.
|
||||
*/
|
||||
registerNgModule(type: Type<any>, scopeInfo: NgModuleScopeInfoFromDecorator): void;
|
||||
|
||||
/**
|
||||
* Clears the scope cache for NgModule or standalone component. This will force re-calculation of
|
||||
* the scope, which could be an expensive operation as it involves aggregating transitive closure.
|
||||
*
|
||||
* The main application of this method is for test beds where we want to clear the cache to
|
||||
* enforce scope update after overriding.
|
||||
*/
|
||||
clearScopeCacheFor(type: ComponentType<any>|NgModuleType): void;
|
||||
|
||||
/**
|
||||
* Returns the scope of NgModule. Mainly to be used by JIT and test bed.
|
||||
*
|
||||
* The scope value here is memoized. To enforce a new calculation bust the cache by using
|
||||
* `clearScopeCacheFor` method.
|
||||
*/
|
||||
getNgModuleScope(type: NgModuleType<any>): NgModuleScope;
|
||||
|
||||
/**
|
||||
* Returns the scope of standalone component. Mainly to be used by JIT.
|
||||
*
|
||||
* The scope value here is memoized. To enforce a new calculation bust the cache by using
|
||||
* `clearScopeCacheFor` method.
|
||||
*/
|
||||
getStandaloneComponentScope(type: ComponentType<any>, imports: Type<any>[]):
|
||||
StandaloneComponentScope;
|
||||
}
|
||||
|
||||
@@ -18,21 +18,35 @@ import {ComponentDependencies, DepsTrackerApi, NgModuleScope, StandaloneComponen
|
||||
class DepsTracker implements DepsTrackerApi {
|
||||
private ownerNgModule = new Map<ComponentType<any>, NgModuleType<any>>();
|
||||
private ngModulesScopeCache = new Map<NgModuleType<any>, NgModuleScope>();
|
||||
private standaloneComponentsScopeCache = new Map<NgModuleType<any>, StandaloneComponentScope>();
|
||||
private standaloneComponentsScopeCache = new Map<ComponentType<any>, StandaloneComponentScope>();
|
||||
|
||||
/** @override */
|
||||
getComponentDependencies(cmp: Type<any>): ComponentDependencies {
|
||||
getComponentDependencies(cmp: ComponentType<any>): ComponentDependencies {
|
||||
// TODO: implement this.
|
||||
return {dependencies: []};
|
||||
}
|
||||
|
||||
/** @override */
|
||||
registerNgModule(type: Type<any>, scopeInfo: NgModuleScopeInfoFromDecorator): void {}
|
||||
|
||||
/** The main deps calculation takes place here. */
|
||||
private getNgModuleScope(m: NgModuleType<any>): NgModuleScope {
|
||||
registerNgModule(type: Type<any>, scopeInfo: NgModuleScopeInfoFromDecorator): void {
|
||||
// TODO: implement this.
|
||||
return {exported: {}, compilation: {}};
|
||||
}
|
||||
|
||||
/** @override */
|
||||
clearScopeCacheFor(type: ComponentType<any>|NgModuleType): void {
|
||||
// TODO: implement this.
|
||||
}
|
||||
|
||||
/** @override */
|
||||
getNgModuleScope(type: NgModuleType<any>): NgModuleScope {
|
||||
// TODO: implement this.
|
||||
return {exported: {directives: [], pipes: []}, compilation: {directives: [], pipes: []}};
|
||||
}
|
||||
|
||||
/** @override */
|
||||
getStandaloneComponentScope(type: ComponentType<any>, imports: Type<any>[]):
|
||||
StandaloneComponentScope {
|
||||
// TODO: implement this.
|
||||
return {compilation: {directives: [], pipes: []}};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user