mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(core): drop RootContext object (#47056)
In a previous refactor, the `RootContext` was update to only contain a reference to a component. This commit perform further refactoring to get rid of the `RootContext` altogether, while storing component reference directly on the root view (without the `RootContext` wrapper). PR Close #47056
This commit is contained in:
parent
7ec196e0fb
commit
a98fa489fb
17 changed files with 117 additions and 210 deletions
|
|
@ -27,7 +27,7 @@ export interface DirectiveDebugMetadata {
|
|||
export function getComponent<T>(element: Element): T | null;
|
||||
|
||||
// @public
|
||||
export function getContext<T extends ({} | RootContext)>(element: Element): T | null;
|
||||
export function getContext<T extends {}>(element: Element): T | null;
|
||||
|
||||
// @public
|
||||
export function getDirectiveMetadata(directiveOrComponentInstance: any): ComponentDebugMetadata | DirectiveDebugMetadata | null;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
"aio-local": {
|
||||
"uncompressed": {
|
||||
"runtime": 4325,
|
||||
"main": 455179,
|
||||
"main": 454655,
|
||||
"polyfills": 33922,
|
||||
"styles": 73640,
|
||||
"light-theme": 78045,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"cli-hello-world": {
|
||||
"uncompressed": {
|
||||
"runtime": 1083,
|
||||
"main": 125276,
|
||||
"main": 124633,
|
||||
"polyfills": 33824
|
||||
}
|
||||
},
|
||||
|
|
@ -19,15 +19,15 @@
|
|||
"cli-hello-world-ivy-compat": {
|
||||
"uncompressed": {
|
||||
"runtime": 1102,
|
||||
"main": 132262,
|
||||
"main": 131619,
|
||||
"polyfills": 33957
|
||||
}
|
||||
},
|
||||
"cli-hello-world-ivy-i18n": {
|
||||
"uncompressed": {
|
||||
"runtime": 926,
|
||||
"main": 124860,
|
||||
"polyfills": 35246
|
||||
"main": 124269,
|
||||
"polyfills": 35252
|
||||
}
|
||||
},
|
||||
"cli-hello-world-lazy": {
|
||||
|
|
@ -41,21 +41,21 @@
|
|||
"forms": {
|
||||
"uncompressed": {
|
||||
"runtime": 1060,
|
||||
"main": 157621,
|
||||
"main": 156626,
|
||||
"polyfills": 33915
|
||||
}
|
||||
},
|
||||
"animations": {
|
||||
"uncompressed": {
|
||||
"runtime": 1070,
|
||||
"main": 156816,
|
||||
"main": 156225,
|
||||
"polyfills": 33814
|
||||
}
|
||||
},
|
||||
"standalone-bootstrap": {
|
||||
"uncompressed": {
|
||||
"runtime": 1090,
|
||||
"main": 83515,
|
||||
"main": 82906,
|
||||
"polyfills": 33945
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,17 +6,17 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ChangeDetectorRef as ViewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref';
|
||||
import {ChangeDetectorRef} from '../change_detection/change_detector_ref';
|
||||
import {Injector} from '../di/injector';
|
||||
import {InjectFlags} from '../di/interface/injector';
|
||||
import {ProviderToken} from '../di/provider_token';
|
||||
import {EnvironmentInjector} from '../di/r3_injector';
|
||||
import {RuntimeError, RuntimeErrorCode} from '../errors';
|
||||
import {Type} from '../interface/type';
|
||||
import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as AbstractComponentRef} from '../linker/component_factory';
|
||||
import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver';
|
||||
import {createElementRef, ElementRef as viewEngine_ElementRef} from '../linker/element_ref';
|
||||
import {NgModuleRef as viewEngine_NgModuleRef} from '../linker/ng_module_factory';
|
||||
import {ComponentFactory as AbstractComponentFactory, ComponentRef as AbstractComponentRef} from '../linker/component_factory';
|
||||
import {ComponentFactoryResolver as AbstractComponentFactoryResolver} from '../linker/component_factory_resolver';
|
||||
import {createElementRef, ElementRef} from '../linker/element_ref';
|
||||
import {NgModuleRef} from '../linker/ng_module_factory';
|
||||
import {RendererFactory2} from '../render/api';
|
||||
import {Sanitizer} from '../sanitization/sanitizer';
|
||||
import {assertDefined, assertIndexInRange} from '../util/assert';
|
||||
|
|
@ -29,12 +29,12 @@ import {diPublicInInjector, getOrCreateNodeInjectorForNode, NodeInjector} from '
|
|||
import {throwProviderNotFoundError} from './errors_di';
|
||||
import {registerPostOrderHooks} from './hooks';
|
||||
import {reportUnknownPropertyError} from './instructions/element_validation';
|
||||
import {addToViewTree, createLView, createTView, getOrCreateTComponentView, getOrCreateTNode, initTNodeFlags, instantiateRootComponent, invokeHostBindingsInCreationMode, locateHostElement, markAsComponentHost, markDirtyIfOnPush, registerHostBindingOpCodes, renderView, setInputsForProperty} from './instructions/shared';
|
||||
import {addToViewTree, createLView, createTView, getOrCreateComponentTView, getOrCreateTNode, initTNodeFlags, instantiateRootComponent, invokeHostBindingsInCreationMode, locateHostElement, markAsComponentHost, markDirtyIfOnPush, registerHostBindingOpCodes, renderView, setInputsForProperty} from './instructions/shared';
|
||||
import {ComponentDef, RenderFlags} from './interfaces/definition';
|
||||
import {PropertyAliasValue, TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType} from './interfaces/node';
|
||||
import {Renderer, RendererFactory} from './interfaces/renderer';
|
||||
import {RElement, RNode} from './interfaces/renderer_dom';
|
||||
import {CONTEXT, HEADER_OFFSET, LView, LViewFlags, RootContext, TVIEW, TViewType} from './interfaces/view';
|
||||
import {CONTEXT, HEADER_OFFSET, LView, LViewFlags, TVIEW, TViewType} from './interfaces/view';
|
||||
import {MATH_ML_NAMESPACE, SVG_NAMESPACE} from './namespaces';
|
||||
import {createElementNode, writeDirectClass, writeDirectStyle} from './node_manipulation';
|
||||
import {extractAttrsAndClassesFromSelector, stringifyCSSSelectorList} from './node_selector_matcher';
|
||||
|
|
@ -45,15 +45,15 @@ import {stringifyForError} from './util/stringify_utils';
|
|||
import {getTNode} from './util/view_utils';
|
||||
import {RootViewRef, ViewRef} from './view_ref';
|
||||
|
||||
export class ComponentFactoryResolver extends viewEngine_ComponentFactoryResolver {
|
||||
export class ComponentFactoryResolver extends AbstractComponentFactoryResolver {
|
||||
/**
|
||||
* @param ngModule The NgModuleRef to which all resolved factories are bound.
|
||||
*/
|
||||
constructor(private ngModule?: viewEngine_NgModuleRef<any>) {
|
||||
constructor(private ngModule?: NgModuleRef<any>) {
|
||||
super();
|
||||
}
|
||||
|
||||
override resolveComponentFactory<T>(component: Type<T>): viewEngine_ComponentFactory<T> {
|
||||
override resolveComponentFactory<T>(component: Type<T>): AbstractComponentFactory<T> {
|
||||
ngDevMode && assertComponentType(component);
|
||||
const componentDef = getComponentDef(component)!;
|
||||
return new ComponentFactory(componentDef, this.ngModule);
|
||||
|
|
@ -102,9 +102,9 @@ class ChainedInjector implements Injector {
|
|||
}
|
||||
|
||||
/**
|
||||
* Render3 implementation of {@link viewEngine_ComponentFactory}.
|
||||
* ComponentFactory interface implementation.
|
||||
*/
|
||||
export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
||||
export class ComponentFactory<T> extends AbstractComponentFactory<T> {
|
||||
override selector: string;
|
||||
override componentType: Type<any>;
|
||||
override ngContentSelectors: string[];
|
||||
|
|
@ -122,8 +122,7 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
|||
* @param componentDef The component definition.
|
||||
* @param ngModule The NgModuleRef to which the factory is bound.
|
||||
*/
|
||||
constructor(
|
||||
private componentDef: ComponentDef<any>, private ngModule?: viewEngine_NgModuleRef<any>) {
|
||||
constructor(private componentDef: ComponentDef<any>, private ngModule?: NgModuleRef<any>) {
|
||||
super();
|
||||
this.componentType = componentDef.type;
|
||||
this.selector = stringifyCSSSelectorList(componentDef.selectors);
|
||||
|
|
@ -134,7 +133,7 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
|||
|
||||
override create(
|
||||
injector: Injector, projectableNodes?: any[][]|undefined, rootSelectorOrNode?: any,
|
||||
environmentInjector?: viewEngine_NgModuleRef<any>|EnvironmentInjector|
|
||||
environmentInjector?: NgModuleRef<any>|EnvironmentInjector|
|
||||
undefined): AbstractComponentRef<T> {
|
||||
environmentInjector = environmentInjector || this.ngModule;
|
||||
|
||||
|
|
@ -173,13 +172,12 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
|||
|
||||
const rootFlags = this.componentDef.onPush ? LViewFlags.Dirty | LViewFlags.IsRoot :
|
||||
LViewFlags.CheckAlways | LViewFlags.IsRoot;
|
||||
const rootContext = createRootContext();
|
||||
|
||||
// Create the root view. Uses empty TView and ContentTemplate.
|
||||
const rootTView = createTView(TViewType.Root, null, null, 1, 0, null, null, null, null, null);
|
||||
const rootLView = createLView(
|
||||
null, rootTView, rootContext, rootFlags, null, null, rendererFactory, hostRenderer,
|
||||
sanitizer, rootViewInjector, null);
|
||||
null, rootTView, null, rootFlags, null, null, rendererFactory, hostRenderer, sanitizer,
|
||||
rootViewInjector, null);
|
||||
|
||||
// rootView is the parent when bootstrapping
|
||||
// TODO(misko): it looks like we are entering view here but we don't really need to as
|
||||
|
|
@ -230,8 +228,8 @@ export class ComponentFactory<T> extends viewEngine_ComponentFactory<T> {
|
|||
// TODO: should LifecycleHooksFeature and other host features be generated by the compiler and
|
||||
// executed here?
|
||||
// Angular 5 reference: https://stackblitz.com/edit/lifecycle-hooks-vcref
|
||||
component = createRootComponent(
|
||||
componentView, this.componentDef, rootLView, rootContext, [LifecycleHooksFeature]);
|
||||
component =
|
||||
createRootComponent(componentView, this.componentDef, rootLView, [LifecycleHooksFeature]);
|
||||
renderView(rootTView, rootLView, null);
|
||||
} finally {
|
||||
leaveView();
|
||||
|
|
@ -252,7 +250,7 @@ const componentFactoryResolver: ComponentFactoryResolver = new ComponentFactoryR
|
|||
*
|
||||
* @returns The ComponentFactoryResolver instance to use
|
||||
*/
|
||||
export function injectComponentFactoryResolver(): viewEngine_ComponentFactoryResolver {
|
||||
export function injectComponentFactoryResolver(): AbstractComponentFactoryResolver {
|
||||
return componentFactoryResolver;
|
||||
}
|
||||
|
||||
|
|
@ -267,12 +265,11 @@ export function injectComponentFactoryResolver(): viewEngine_ComponentFactoryRes
|
|||
export class ComponentRef<T> extends AbstractComponentRef<T> {
|
||||
override instance: T;
|
||||
override hostView: ViewRef<T>;
|
||||
override changeDetectorRef: ViewEngine_ChangeDetectorRef;
|
||||
override changeDetectorRef: ChangeDetectorRef;
|
||||
override componentType: Type<T>;
|
||||
|
||||
constructor(
|
||||
componentType: Type<T>, instance: T, public location: viewEngine_ElementRef,
|
||||
private _rootLView: LView,
|
||||
componentType: Type<T>, instance: T, public location: ElementRef, private _rootLView: LView,
|
||||
private _tNode: TElementNode|TContainerNode|TElementContainerNode) {
|
||||
super();
|
||||
this.instance = instance;
|
||||
|
|
@ -361,7 +358,7 @@ export function createRootComponentView(
|
|||
|
||||
const viewRenderer = rendererFactory.createRenderer(rNode, def);
|
||||
const componentView = createLView(
|
||||
rootView, getOrCreateTComponentView(def), null,
|
||||
rootView, getOrCreateComponentTView(def), null,
|
||||
def.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways, rootView[index], tNode,
|
||||
rendererFactory, viewRenderer, sanitizer || null, null, null);
|
||||
|
||||
|
|
@ -382,14 +379,15 @@ export function createRootComponentView(
|
|||
* renderComponent() and ViewContainerRef.createComponent().
|
||||
*/
|
||||
export function createRootComponent<T>(
|
||||
componentView: LView, componentDef: ComponentDef<T>, rootLView: LView, rootContext: RootContext,
|
||||
componentView: LView, componentDef: ComponentDef<T>, rootLView: LView,
|
||||
hostFeatures: HostFeature[]|null): any {
|
||||
const tView = rootLView[TVIEW];
|
||||
// Create directive instance with factory() and store at next index in viewData
|
||||
const component = instantiateRootComponent(tView, rootLView, componentDef);
|
||||
|
||||
rootContext.components.push(component);
|
||||
componentView[CONTEXT] = component;
|
||||
// Root view only contains an instance of this component,
|
||||
// so we use a reference to that component instance as a context.
|
||||
componentView[CONTEXT] = rootLView[CONTEXT] = component;
|
||||
|
||||
if (hostFeatures !== null) {
|
||||
for (const feature of hostFeatures) {
|
||||
|
|
@ -421,10 +419,6 @@ export function createRootComponent<T>(
|
|||
return component;
|
||||
}
|
||||
|
||||
function createRootContext(): RootContext {
|
||||
return {components: []};
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to enable lifecycle hooks on the root component.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import {Renderer, RendererFactory} from '../interfaces/renderer';
|
|||
import {RComment, RElement, RNode, RText} from '../interfaces/renderer_dom';
|
||||
import {SanitizerFn} from '../interfaces/sanitization';
|
||||
import {isComponentDef, isComponentHost, isContentQueryHost, isRootView} from '../interfaces/type_checks';
|
||||
import {CHILD_HEAD, CHILD_TAIL, CLEANUP, CONTEXT, DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, EMBEDDED_VIEW_INJECTOR, FLAGS, HEADER_OFFSET, HOST, HostBindingOpCodes, ID, InitPhaseState, INJECTOR, LView, LViewFlags, NEXT, PARENT, RENDERER, RENDERER_FACTORY, RootContext, SANITIZER, T_HOST, TData, TRANSPLANTED_VIEWS_TO_REFRESH, TVIEW, TView, TViewType} from '../interfaces/view';
|
||||
import {CHILD_HEAD, CHILD_TAIL, CLEANUP, CONTEXT, DECLARATION_COMPONENT_VIEW, DECLARATION_VIEW, EMBEDDED_VIEW_INJECTOR, FLAGS, HEADER_OFFSET, HOST, HostBindingOpCodes, ID, InitPhaseState, INJECTOR, LView, LViewFlags, NEXT, PARENT, RENDERER, RENDERER_FACTORY, SANITIZER, T_HOST, TData, TRANSPLANTED_VIEWS_TO_REFRESH, TVIEW, TView, TViewType} from '../interfaces/view';
|
||||
import {assertPureTNodeType, assertTNodeType} from '../node_assert';
|
||||
import {updateTextNode} from '../node_manipulation';
|
||||
import {isInlineTemplate, isNodeMatchingSelectorList} from '../node_selector_matcher';
|
||||
|
|
@ -480,30 +480,6 @@ export function refreshView<T>(
|
|||
}
|
||||
}
|
||||
|
||||
export function renderComponentOrTemplate<T>(
|
||||
tView: TView, lView: LView, templateFn: ComponentTemplate<{}>|null, context: T) {
|
||||
const rendererFactory = lView[RENDERER_FACTORY];
|
||||
|
||||
// Check no changes mode is a dev only mode used to verify that bindings have not changed
|
||||
// since they were assigned. We do not want to invoke renderer factory functions in that mode
|
||||
// to avoid any possible side-effects.
|
||||
const checkNoChangesMode = !!ngDevMode && isInCheckNoChangesMode();
|
||||
const creationModeIsActive = isCreationMode(lView);
|
||||
try {
|
||||
if (!checkNoChangesMode && !creationModeIsActive && rendererFactory.begin) {
|
||||
rendererFactory.begin();
|
||||
}
|
||||
if (creationModeIsActive) {
|
||||
renderView(tView, lView, context);
|
||||
}
|
||||
refreshView(tView, lView, templateFn, context);
|
||||
} finally {
|
||||
if (!checkNoChangesMode && !creationModeIsActive && rendererFactory.end) {
|
||||
rendererFactory.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function executeTemplate<T>(
|
||||
tView: TView, lView: LView<T>, templateFn: ComponentTemplate<T>, rf: RenderFlags, context: T) {
|
||||
const prevSelectedIndex = getSelectedIndex();
|
||||
|
|
@ -586,7 +562,7 @@ export function saveResolvedLocalsInData(
|
|||
* @param def ComponentDef
|
||||
* @returns TView
|
||||
*/
|
||||
export function getOrCreateTComponentView(def: ComponentDef<any>): TView {
|
||||
export function getOrCreateComponentTView(def: ComponentDef<any>): TView {
|
||||
const tView = def.tView;
|
||||
|
||||
// Create a TView if there isn't one, or recreate it if the first create pass didn't
|
||||
|
|
@ -1420,7 +1396,7 @@ function configureViewWithDirective<T>(
|
|||
|
||||
function addComponentLogic<T>(lView: LView, hostTNode: TElementNode, def: ComponentDef<T>): void {
|
||||
const native = getNativeByTNode(hostTNode, lView) as RElement;
|
||||
const tView = getOrCreateTComponentView(def);
|
||||
const tView = getOrCreateComponentTView(def);
|
||||
|
||||
// Only component views should be added to the view tree directly. Embedded views are
|
||||
// accessed through their containers because they may be removed / re-added later.
|
||||
|
|
@ -1791,62 +1767,33 @@ export function markViewDirty(lView: LView): LView|null {
|
|||
return null;
|
||||
}
|
||||
|
||||
export function tickRootContext(rootContext: RootContext) {
|
||||
for (let i = 0; i < rootContext.components.length; i++) {
|
||||
const rootComponent = rootContext.components[i];
|
||||
const lView = readPatchedLView(rootComponent);
|
||||
// We might not have an `LView` if the component was destroyed.
|
||||
if (lView !== null) {
|
||||
const tView = lView[TVIEW];
|
||||
renderComponentOrTemplate(tView, lView, tView.template, rootComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function detectChangesInternal<T>(tView: TView, lView: LView, context: T) {
|
||||
export function detectChangesInternal<T>(
|
||||
tView: TView, lView: LView, context: T, notifyErrorHandler = true) {
|
||||
const rendererFactory = lView[RENDERER_FACTORY];
|
||||
if (rendererFactory.begin) rendererFactory.begin();
|
||||
|
||||
// Check no changes mode is a dev only mode used to verify that bindings have not changed
|
||||
// since they were assigned. We do not want to invoke renderer factory functions in that mode
|
||||
// to avoid any possible side-effects.
|
||||
const checkNoChangesMode = !!ngDevMode && isInCheckNoChangesMode();
|
||||
|
||||
if (!checkNoChangesMode && rendererFactory.begin) rendererFactory.begin();
|
||||
try {
|
||||
refreshView(tView, lView, tView.template, context);
|
||||
} catch (error) {
|
||||
handleError(lView, error);
|
||||
if (notifyErrorHandler) {
|
||||
handleError(lView, error);
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
if (rendererFactory.end) rendererFactory.end();
|
||||
if (!checkNoChangesMode && rendererFactory.end) rendererFactory.end();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronously perform change detection on a root view and its components.
|
||||
*
|
||||
* @param lView The view which the change detection should be performed on.
|
||||
*/
|
||||
export function detectChangesInRootView(lView: LView): void {
|
||||
tickRootContext(lView[CONTEXT] as RootContext);
|
||||
}
|
||||
|
||||
export function checkNoChangesInternal<T>(tView: TView, view: LView, context: T) {
|
||||
export function checkNoChangesInternal<T>(
|
||||
tView: TView, lView: LView, context: T, notifyErrorHandler = true) {
|
||||
setIsInCheckNoChangesMode(true);
|
||||
try {
|
||||
detectChangesInternal(tView, view, context);
|
||||
} finally {
|
||||
setIsInCheckNoChangesMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the change detector on a root view and its components, and throws if any changes are
|
||||
* detected.
|
||||
*
|
||||
* This is used in development mode to verify that running change detection doesn't
|
||||
* introduce other changes.
|
||||
*
|
||||
* @param lView The view which the change detection should be checked on.
|
||||
*/
|
||||
export function checkNoChangesInRootView(lView: LView): void {
|
||||
setIsInCheckNoChangesMode(true);
|
||||
try {
|
||||
detectChangesInRootView(lView);
|
||||
detectChangesInternal(tView, lView, context, notifyErrorHandler);
|
||||
} finally {
|
||||
setIsInCheckNoChangesMode(false);
|
||||
}
|
||||
|
|
@ -1859,7 +1806,6 @@ function executeViewQueryFn<T>(
|
|||
viewQueryFn(flags, component);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////
|
||||
//// Bindings & interpolations
|
||||
///////////////////////////////
|
||||
|
|
|
|||
|
|
@ -175,8 +175,8 @@ export interface LView<T = unknown> extends Array<any> {
|
|||
/**
|
||||
* - For dynamic views, this is the context with which to render the template (e.g.
|
||||
* `NgForContext`), or `{}` if not defined explicitly.
|
||||
* - For root view of the root component the context contains change detection data.
|
||||
* - For non-root components, the context is the component instance,
|
||||
* - For root view of the root component it's a reference to the component instance itself.
|
||||
* - For components, the context is a reference to the component instance itself.
|
||||
* - For inline views, the context is null.
|
||||
*/
|
||||
[CONTEXT]: T;
|
||||
|
|
@ -789,16 +789,6 @@ export interface TView {
|
|||
incompleteFirstPass: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains information which is shared for all bootstrapped components.
|
||||
*/
|
||||
export interface RootContext<T = unknown> {
|
||||
/**
|
||||
* The components that were instantiated within this context.
|
||||
*/
|
||||
components: T[];
|
||||
}
|
||||
|
||||
/** Single hook callback function. */
|
||||
export type HookFn = () => void;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,13 +15,11 @@ import {discoverLocalRefs, getComponentAtNodeIndex, getDirectivesAtNodeIndex, ge
|
|||
import {getComponentDef, getDirectiveDef} from '../definition';
|
||||
import {NodeInjector} from '../di';
|
||||
import {buildDebugNode} from '../instructions/lview_debug';
|
||||
import {LContext} from '../interfaces/context';
|
||||
import {DirectiveDef} from '../interfaces/definition';
|
||||
import {TElementNode, TNode, TNodeProviderIndexes} from '../interfaces/node';
|
||||
import {isLView} from '../interfaces/type_checks';
|
||||
import {CLEANUP, CONTEXT, DebugNode, FLAGS, LView, LViewFlags, RootContext, T_HOST, TVIEW, TViewType} from '../interfaces/view';
|
||||
import {CLEANUP, CONTEXT, DebugNode, FLAGS, LView, LViewFlags, T_HOST, TVIEW, TViewType} from '../interfaces/view';
|
||||
|
||||
import {stringifyForError} from './stringify_utils';
|
||||
import {getLViewParent, getRootContext} from './view_traversal_utils';
|
||||
import {getTNode, unwrapRNode} from './view_utils';
|
||||
|
||||
|
|
@ -83,7 +81,7 @@ export function getComponent<T>(element: Element): T|null {
|
|||
* @publicApi
|
||||
* @globalApi ng
|
||||
*/
|
||||
export function getContext<T extends({} | RootContext)>(element: Element): T|null {
|
||||
export function getContext<T extends {}>(element: Element): T|null {
|
||||
assertDomElement(element);
|
||||
const context = getLContext(element)!;
|
||||
const lView = context ? context.lView : null;
|
||||
|
|
@ -130,7 +128,7 @@ export function getOwningComponent<T>(elementOrDir: Element|{}): T|null {
|
|||
*/
|
||||
export function getRootComponents(elementOrDir: Element|{}): {}[] {
|
||||
const lView = readPatchedLView<{}>(elementOrDir);
|
||||
return lView !== null ? [...getRootContext(lView).components as unknown as {}[]] : [];
|
||||
return lView !== null ? [getRootContext(lView)] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import {assertLView} from '../assert';
|
|||
import {readPatchedLView} from '../context_discovery';
|
||||
import {LContainer} from '../interfaces/container';
|
||||
import {isLContainer, isLView} from '../interfaces/type_checks';
|
||||
import {CHILD_HEAD, CONTEXT, FLAGS, LView, LViewFlags, NEXT, PARENT, RootContext} from '../interfaces/view';
|
||||
import {CHILD_HEAD, CONTEXT, FLAGS, LView, LViewFlags, NEXT, PARENT} from '../interfaces/view';
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -42,17 +42,17 @@ export function getRootView<T>(componentOrLView: LView|{}): LView<T> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the `RootContext` instance that is associated with
|
||||
* the application where the target is situated. It does this by walking the parent views until it
|
||||
* gets to the root view, then getting the context off of that.
|
||||
* Returns the context information associated with the application where the target is situated. It
|
||||
* does this by walking the parent views until it gets to the root view, then getting the context
|
||||
* off of that.
|
||||
*
|
||||
* @param viewOrComponent the `LView` or component to get the root context for.
|
||||
*/
|
||||
export function getRootContext<T>(viewOrComponent: LView<T>|{}): RootContext {
|
||||
export function getRootContext<T>(viewOrComponent: LView<T>|{}): T {
|
||||
const rootView = getRootView(viewOrComponent);
|
||||
ngDevMode &&
|
||||
assertDefined(rootView[CONTEXT], 'RootView has no context. Perhaps it is disconnected?');
|
||||
return rootView[CONTEXT] as RootContext;
|
||||
assertDefined(rootView[CONTEXT], 'Root view has no context. Perhaps it is disconnected?');
|
||||
return rootView[CONTEXT] as T;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {removeFromArray} from '../util/array_utils';
|
|||
import {assertEqual} from '../util/assert';
|
||||
|
||||
import {collectNativeNodes} from './collect_native_nodes';
|
||||
import {checkNoChangesInRootView, checkNoChangesInternal, detectChangesInRootView, detectChangesInternal, markViewDirty, storeCleanupWithContext} from './instructions/shared';
|
||||
import {checkNoChangesInternal, detectChangesInternal, markViewDirty, storeCleanupWithContext} from './instructions/shared';
|
||||
import {CONTAINER_HEADER_OFFSET, VIEW_REFS} from './interfaces/container';
|
||||
import {isLContainer} from './interfaces/type_checks';
|
||||
import {CONTEXT, FLAGS, LView, LViewFlags, PARENT, TVIEW} from './interfaces/view';
|
||||
|
|
@ -317,12 +317,18 @@ export class RootViewRef<T> extends ViewRef<T> {
|
|||
}
|
||||
|
||||
override detectChanges(): void {
|
||||
detectChangesInRootView(this._view);
|
||||
const lView = this._view;
|
||||
const tView = lView[TVIEW];
|
||||
const context = lView[CONTEXT];
|
||||
detectChangesInternal(tView, lView, context, false);
|
||||
}
|
||||
|
||||
override checkNoChanges(): void {
|
||||
if (ngDevMode) {
|
||||
checkNoChangesInRootView(this._view);
|
||||
const lView = this._view;
|
||||
const tView = lView[TVIEW];
|
||||
const context = lView[CONTEXT];
|
||||
checkNoChangesInternal(tView, lView, context, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -707,6 +707,9 @@
|
|||
{
|
||||
"name": "detachMovedView"
|
||||
},
|
||||
{
|
||||
"name": "detectChangesInternal"
|
||||
},
|
||||
{
|
||||
"name": "diPublicInInjector"
|
||||
},
|
||||
|
|
@ -833,15 +836,15 @@
|
|||
{
|
||||
"name": "getNullInjector"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateComponentTView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateInjectable"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateNodeInjectorForNode"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTComponentView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTNode"
|
||||
},
|
||||
|
|
@ -1160,9 +1163,6 @@
|
|||
{
|
||||
"name": "promise"
|
||||
},
|
||||
{
|
||||
"name": "readPatchedLView"
|
||||
},
|
||||
{
|
||||
"name": "refCount"
|
||||
},
|
||||
|
|
@ -1205,9 +1205,6 @@
|
|||
{
|
||||
"name": "renderComponent"
|
||||
},
|
||||
{
|
||||
"name": "renderComponentOrTemplate"
|
||||
},
|
||||
{
|
||||
"name": "renderView"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -494,6 +494,9 @@
|
|||
{
|
||||
"name": "detachMovedView"
|
||||
},
|
||||
{
|
||||
"name": "detectChangesInternal"
|
||||
},
|
||||
{
|
||||
"name": "diPublicInInjector"
|
||||
},
|
||||
|
|
@ -611,15 +614,15 @@
|
|||
{
|
||||
"name": "getNullInjector"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateComponentTView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateInjectable"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateNodeInjectorForNode"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTComponentView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTNode"
|
||||
},
|
||||
|
|
@ -866,9 +869,6 @@
|
|||
{
|
||||
"name": "promise"
|
||||
},
|
||||
{
|
||||
"name": "readPatchedLView"
|
||||
},
|
||||
{
|
||||
"name": "refCount"
|
||||
},
|
||||
|
|
@ -905,9 +905,6 @@
|
|||
{
|
||||
"name": "renderComponent"
|
||||
},
|
||||
{
|
||||
"name": "renderComponentOrTemplate"
|
||||
},
|
||||
{
|
||||
"name": "renderView"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -728,6 +728,9 @@
|
|||
{
|
||||
"name": "detachView"
|
||||
},
|
||||
{
|
||||
"name": "detectChangesInternal"
|
||||
},
|
||||
{
|
||||
"name": "diPublicInInjector"
|
||||
},
|
||||
|
|
@ -887,6 +890,9 @@
|
|||
{
|
||||
"name": "getNullInjector"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateComponentTView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateInjectable"
|
||||
},
|
||||
|
|
@ -896,9 +902,6 @@
|
|||
{
|
||||
"name": "getOrCreateNodeInjectorForNode"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTComponentView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTNode"
|
||||
},
|
||||
|
|
@ -1304,9 +1307,6 @@
|
|||
{
|
||||
"name": "providerToFactory"
|
||||
},
|
||||
{
|
||||
"name": "readPatchedLView"
|
||||
},
|
||||
{
|
||||
"name": "refCount"
|
||||
},
|
||||
|
|
@ -1355,9 +1355,6 @@
|
|||
{
|
||||
"name": "renderComponent"
|
||||
},
|
||||
{
|
||||
"name": "renderComponentOrTemplate"
|
||||
},
|
||||
{
|
||||
"name": "renderView"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -698,6 +698,9 @@
|
|||
{
|
||||
"name": "detachView"
|
||||
},
|
||||
{
|
||||
"name": "detectChangesInternal"
|
||||
},
|
||||
{
|
||||
"name": "diPublicInInjector"
|
||||
},
|
||||
|
|
@ -848,6 +851,9 @@
|
|||
{
|
||||
"name": "getNullInjector"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateComponentTView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateInjectable"
|
||||
},
|
||||
|
|
@ -857,9 +863,6 @@
|
|||
{
|
||||
"name": "getOrCreateNodeInjectorForNode"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTComponentView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTNode"
|
||||
},
|
||||
|
|
@ -1268,9 +1271,6 @@
|
|||
{
|
||||
"name": "providerToFactory"
|
||||
},
|
||||
{
|
||||
"name": "readPatchedLView"
|
||||
},
|
||||
{
|
||||
"name": "refCount"
|
||||
},
|
||||
|
|
@ -1319,9 +1319,6 @@
|
|||
{
|
||||
"name": "renderComponent"
|
||||
},
|
||||
{
|
||||
"name": "renderComponentOrTemplate"
|
||||
},
|
||||
{
|
||||
"name": "renderStringify"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -353,6 +353,9 @@
|
|||
{
|
||||
"name": "detachMovedView"
|
||||
},
|
||||
{
|
||||
"name": "detectChangesInternal"
|
||||
},
|
||||
{
|
||||
"name": "empty"
|
||||
},
|
||||
|
|
@ -635,9 +638,6 @@
|
|||
{
|
||||
"name": "promise"
|
||||
},
|
||||
{
|
||||
"name": "readPatchedLView"
|
||||
},
|
||||
{
|
||||
"name": "refCount"
|
||||
},
|
||||
|
|
@ -668,9 +668,6 @@
|
|||
{
|
||||
"name": "renderComponent"
|
||||
},
|
||||
{
|
||||
"name": "renderComponentOrTemplate"
|
||||
},
|
||||
{
|
||||
"name": "renderView"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -905,6 +905,9 @@
|
|||
{
|
||||
"name": "detachView"
|
||||
},
|
||||
{
|
||||
"name": "detectChangesInternal"
|
||||
},
|
||||
{
|
||||
"name": "diPublicInInjector"
|
||||
},
|
||||
|
|
@ -1115,6 +1118,9 @@
|
|||
{
|
||||
"name": "getNullInjector"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateComponentTView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateInjectable"
|
||||
},
|
||||
|
|
@ -1127,9 +1133,6 @@
|
|||
{
|
||||
"name": "getOrCreateRouteInjectorIfNeeded"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTComponentView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTNode"
|
||||
},
|
||||
|
|
@ -1313,9 +1316,6 @@
|
|||
{
|
||||
"name": "isContentQueryHost"
|
||||
},
|
||||
{
|
||||
"name": "isCreationMode"
|
||||
},
|
||||
{
|
||||
"name": "isCssClassMatching"
|
||||
},
|
||||
|
|
@ -1559,9 +1559,6 @@
|
|||
{
|
||||
"name": "provideRoutes"
|
||||
},
|
||||
{
|
||||
"name": "readPatchedLView"
|
||||
},
|
||||
{
|
||||
"name": "redirectIfUrlTree"
|
||||
},
|
||||
|
|
@ -1604,9 +1601,6 @@
|
|||
{
|
||||
"name": "renderComponent"
|
||||
},
|
||||
{
|
||||
"name": "renderComponentOrTemplate"
|
||||
},
|
||||
{
|
||||
"name": "renderStringify"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -422,6 +422,9 @@
|
|||
{
|
||||
"name": "detachMovedView"
|
||||
},
|
||||
{
|
||||
"name": "detectChangesInternal"
|
||||
},
|
||||
{
|
||||
"name": "empty"
|
||||
},
|
||||
|
|
@ -722,9 +725,6 @@
|
|||
{
|
||||
"name": "promise"
|
||||
},
|
||||
{
|
||||
"name": "readPatchedLView"
|
||||
},
|
||||
{
|
||||
"name": "refCount"
|
||||
},
|
||||
|
|
@ -758,9 +758,6 @@
|
|||
{
|
||||
"name": "renderComponent"
|
||||
},
|
||||
{
|
||||
"name": "renderComponentOrTemplate"
|
||||
},
|
||||
{
|
||||
"name": "renderView"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -608,6 +608,9 @@
|
|||
{
|
||||
"name": "detachView"
|
||||
},
|
||||
{
|
||||
"name": "detectChangesInternal"
|
||||
},
|
||||
{
|
||||
"name": "diPublicInInjector"
|
||||
},
|
||||
|
|
@ -740,6 +743,9 @@
|
|||
{
|
||||
"name": "getNullInjector"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateComponentTView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateInjectable"
|
||||
},
|
||||
|
|
@ -749,9 +755,6 @@
|
|||
{
|
||||
"name": "getOrCreateNodeInjectorForNode"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTComponentView"
|
||||
},
|
||||
{
|
||||
"name": "getOrCreateTNode"
|
||||
},
|
||||
|
|
@ -1079,9 +1082,6 @@
|
|||
{
|
||||
"name": "promise"
|
||||
},
|
||||
{
|
||||
"name": "readPatchedLView"
|
||||
},
|
||||
{
|
||||
"name": "refCount"
|
||||
},
|
||||
|
|
@ -1118,9 +1118,6 @@
|
|||
{
|
||||
"name": "renderComponent"
|
||||
},
|
||||
{
|
||||
"name": "renderComponentOrTemplate"
|
||||
},
|
||||
{
|
||||
"name": "renderStringify"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue