refactor(core): create consistent naming scheme across classes (#21403)
PR Close #21403
This commit is contained in:
parent
908129e9a2
commit
fc3e7e0381
|
@ -14,8 +14,8 @@ import {EmbeddedViewRef as viewEngine_EmbeddedViewRef} from '../linker/view_ref'
|
|||
|
||||
import {assertNotNull} from './assert';
|
||||
import {ComponentDef, ComponentType} from './definition_interfaces';
|
||||
import {NG_HOST_SYMBOL, createError, createViewState, directive, enterView, hostElement, leaveView, locateHostElement, renderComponentOrTemplate} from './instructions';
|
||||
import {LElement} from './interfaces';
|
||||
import {NG_HOST_SYMBOL, createError, createLView, directive, enterView, hostElement, leaveView, locateHostElement, renderComponentOrTemplate} from './instructions';
|
||||
import {LElementNode} from './interfaces';
|
||||
import {RElement, Renderer3, RendererFactory3, domRendererFactory3} from './renderer';
|
||||
import {notImplemented, stringify} from './util';
|
||||
|
||||
|
@ -170,7 +170,7 @@ export function renderComponent<T>(
|
|||
let component: T;
|
||||
const hostNode = locateHostElement(rendererFactory, opts.host || componentDef.tag);
|
||||
const oldView = enterView(
|
||||
createViewState(-1, rendererFactory.createRenderer(hostNode, componentDef.rendererType), []),
|
||||
createLView(-1, rendererFactory.createRenderer(hostNode, componentDef.rendererType), []),
|
||||
null !);
|
||||
try {
|
||||
// Create element node at index 0 in data array
|
||||
|
@ -188,7 +188,7 @@ export function renderComponent<T>(
|
|||
|
||||
export function detectChanges<T>(component: T) {
|
||||
ngDevMode && assertNotNull(component, 'component');
|
||||
const hostNode = (component as any)[NG_HOST_SYMBOL] as LElement;
|
||||
const hostNode = (component as any)[NG_HOST_SYMBOL] as LElementNode;
|
||||
if (ngDevMode && !hostNode) {
|
||||
createError('Not a directive instance', component);
|
||||
}
|
||||
|
@ -208,5 +208,5 @@ export function markDirty<T>(
|
|||
}
|
||||
|
||||
export function getHostElement<T>(component: T): RElement {
|
||||
return ((component as any)[NG_HOST_SYMBOL] as LElement).native;
|
||||
return ((component as any)[NG_HOST_SYMBOL] as LElementNode).native;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import {EmbeddedViewRef as viewEngine_EmbeddedViewRef, ViewRef as viewEngine_Vie
|
|||
import {Type} from '../type';
|
||||
|
||||
import {ComponentTemplate, DirectiveDef} from './definition_interfaces';
|
||||
import {LContainer, LElement, LNodeFlags, LNodeInjector} from './interfaces';
|
||||
import {LContainerNode, LElementNode, LInjector, LNodeFlags} from './interfaces';
|
||||
import {assertNodeType} from './node_assert';
|
||||
import {notImplemented, stringify} from './util';
|
||||
|
||||
|
@ -48,7 +48,7 @@ let nextNgElementId = 0;
|
|||
* @param injector The node injector in which the directive should be registered
|
||||
* @param type The directive to register
|
||||
*/
|
||||
export function bloomAdd(injector: LNodeInjector, type: Type<any>): void {
|
||||
export function bloomAdd(injector: LInjector, type: Type<any>): void {
|
||||
let id: number|undefined = (type as any)[NG_ELEMENT_ID];
|
||||
|
||||
// Set a unique ID on the directive type, so if something tries to inject the directive,
|
||||
|
@ -92,7 +92,7 @@ export function bloomAdd(injector: LNodeInjector, type: Type<any>): void {
|
|||
* @param node for which an injector should be retrieved / created.
|
||||
* @returns Node injector
|
||||
*/
|
||||
export function getOrCreateNodeInjectorForNode(node: LElement | LContainer): LNodeInjector {
|
||||
export function getOrCreateNodeInjectorForNode(node: LElementNode | LContainerNode): LInjector {
|
||||
const nodeInjector = node.nodeInjector;
|
||||
const parentInjector = node.parent && node.parent.nodeInjector;
|
||||
if (nodeInjector != parentInjector) {
|
||||
|
@ -146,7 +146,7 @@ function createInjectionError(text: string, token: any) {
|
|||
* @param di The node injector in which a directive will be added
|
||||
* @param def The definition of the directive to be made public
|
||||
*/
|
||||
export function diPublicInInjector(di: LNodeInjector, def: DirectiveDef<any>): void {
|
||||
export function diPublicInInjector(di: LInjector, def: DirectiveDef<any>): void {
|
||||
bloomAdd(di, def.type);
|
||||
}
|
||||
|
||||
|
@ -167,8 +167,7 @@ export function diPublicInInjector(di: LNodeInjector, def: DirectiveDef<any>): v
|
|||
* @param flags Injection flags (e.g. CheckParent)
|
||||
* @returns The instance found
|
||||
*/
|
||||
export function getOrCreateInjectable<T>(
|
||||
di: LNodeInjector, token: Type<T>, flags?: InjectFlags): T {
|
||||
export function getOrCreateInjectable<T>(di: LInjector, token: Type<T>, flags?: InjectFlags): T {
|
||||
const bloomHash = bloomHashBit(token);
|
||||
|
||||
// If the token has a bloom hash, then it is a directive that is public to the injection system
|
||||
|
@ -180,7 +179,7 @@ export function getOrCreateInjectable<T>(
|
|||
}
|
||||
moduleInjector.get(token);
|
||||
} else {
|
||||
let injector: LNodeInjector|null = di;
|
||||
let injector: LInjector|null = di;
|
||||
|
||||
while (injector) {
|
||||
// Get the closest potential matching injector (upwards in the injector tree) that
|
||||
|
@ -265,8 +264,8 @@ function bloomHashBit(type: Type<any>): number|null {
|
|||
* @param bloomBit The bit to check in each injector's bloom filter
|
||||
* @returns An injector that might have the directive
|
||||
*/
|
||||
export function bloomFindPossibleInjector(
|
||||
startInjector: LNodeInjector, bloomBit: number): LNodeInjector|null {
|
||||
export function bloomFindPossibleInjector(startInjector: LInjector, bloomBit: number): LInjector|
|
||||
null {
|
||||
// Create a mask that targets the specific bit associated with the directive we're looking for.
|
||||
// JS bit operations are 32 bits, so this will be a number between 2^0 and 2^31, corresponding
|
||||
// to bit positions 0 - 31 in a 32 bit integer.
|
||||
|
@ -274,7 +273,7 @@ export function bloomFindPossibleInjector(
|
|||
|
||||
// Traverse up the injector tree until we find a potential match or until we know there *isn't* a
|
||||
// match.
|
||||
let injector: LNodeInjector|null = startInjector;
|
||||
let injector: LInjector|null = startInjector;
|
||||
while (injector) {
|
||||
// Our bloom filter size is 128 bits, which is four 32-bit bloom filter buckets:
|
||||
// bf0 = [0 - 31], bf1 = [32 - 63], bf2 = [64 - 95], bf3 = [96 - 127]
|
||||
|
@ -307,7 +306,7 @@ export function bloomFindPossibleInjector(
|
|||
* @param di The node injector where we should store a created ElementRef
|
||||
* @returns The ElementRef instance to use
|
||||
*/
|
||||
export function getOrCreateElementRef(di: LNodeInjector): viewEngine_ElementRef {
|
||||
export function getOrCreateElementRef(di: LInjector): viewEngine_ElementRef {
|
||||
return di.elementRef || (di.elementRef = new ElementRef(di.node.native));
|
||||
}
|
||||
|
||||
|
@ -324,9 +323,9 @@ class ElementRef implements viewEngine_ElementRef {
|
|||
* @param di The node injector where we should store a created TemplateRef
|
||||
* @returns The TemplateRef instance to use
|
||||
*/
|
||||
export function getOrCreateTemplateRef<T>(di: LNodeInjector): viewEngine_TemplateRef<T> {
|
||||
export function getOrCreateTemplateRef<T>(di: LInjector): viewEngine_TemplateRef<T> {
|
||||
ngDevMode && assertNodeType(di.node, LNodeFlags.Container);
|
||||
const data = (di.node as LContainer).data;
|
||||
const data = (di.node as LContainerNode).data;
|
||||
return di.templateRef ||
|
||||
(di.templateRef = new TemplateRef<any>(getOrCreateElementRef(di), data.template));
|
||||
}
|
||||
|
@ -348,8 +347,9 @@ class TemplateRef<T> implements viewEngine_TemplateRef<T> {
|
|||
*
|
||||
* @returns The ViewContainerRef instance to use
|
||||
*/
|
||||
export function getOrCreateContainerRef(di: LNodeInjector): viewEngine_ViewContainerRef {
|
||||
return di.viewContainerRef || (di.viewContainerRef = new ViewContainerRef(di.node as LContainer));
|
||||
export function getOrCreateContainerRef(di: LInjector): viewEngine_ViewContainerRef {
|
||||
return di.viewContainerRef ||
|
||||
(di.viewContainerRef = new ViewContainerRef(di.node as LContainerNode));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -361,7 +361,7 @@ class ViewContainerRef implements viewEngine_ViewContainerRef {
|
|||
injector: Injector;
|
||||
parentInjector: Injector;
|
||||
|
||||
constructor(node: LContainer) {}
|
||||
constructor(node: LContainerNode) {}
|
||||
|
||||
clear(): void { throw notImplemented(); }
|
||||
get(index: number): viewEngine_ViewRef|null { throw notImplemented(); }
|
||||
|
|
|
@ -14,15 +14,15 @@ import {ViewContainerRef} from '../linker/view_container_ref';
|
|||
import {Type} from '../type';
|
||||
|
||||
import {assertEqual, assertLessThan, assertNotEqual, assertNotNull} from './assert';
|
||||
import {ContainerState, CssSelector, LContainer, LElement, LNode, LNodeFlags, LNodeInjector, LProjection, LText, LView, ProjectionState, QueryReadType, QueryState, ViewState} from './interfaces';
|
||||
import {CssSelector, LContainer, LContainerNode, LElementNode, LInjector, LNode, LNodeFlags, LProjection, LProjectionNode, LQuery, LTextNode, LView, LViewNode, QueryReadType} from './interfaces';
|
||||
|
||||
import {NgStaticData, LNodeStatic, LContainerStatic, InitialInputData, InitialInputs, PropertyAliases, PropertyAliasValue,} from './l_node_static';
|
||||
import {NgStaticData, TNode, TContainerNode, InitialInputData, InitialInputs, PropertyAliases, PropertyAliasValue,} from './t_node';
|
||||
import {assertNodeType} from './node_assert';
|
||||
import {appendChild, insertChild, insertView, processProjectedNode, removeView} from './node_manipulation';
|
||||
import {isNodeMatchingSelector} from './node_selector_matcher';
|
||||
import {ComponentDef, ComponentTemplate, ComponentType, DirectiveDef} from './definition_interfaces';
|
||||
import {InjectFlags, diPublicInInjector, getOrCreateNodeInjectorForNode, getOrCreateElementRef, getOrCreateTemplateRef, getOrCreateContainerRef, getOrCreateInjectable} from './di';
|
||||
import {QueryList, QueryState_} from './query';
|
||||
import {QueryList, LQuery_} from './query';
|
||||
import {RComment, RElement, RText, Renderer3, RendererFactory3, ProceduralRenderer3, ObjectOrientedRenderer3, RendererStyleFlags3} from './renderer';
|
||||
import {isDifferent, stringify} from './util';
|
||||
|
||||
|
@ -87,14 +87,12 @@ let isParent: boolean;
|
|||
*/
|
||||
let ngStaticData: NgStaticData;
|
||||
|
||||
/**
|
||||
* State of the current view being processed.
|
||||
*/
|
||||
let currentView: ViewState;
|
||||
// The initialization has to be after the `let`, otherwise `createViewState` can't see `let`.
|
||||
currentView = createViewState(null !, null !, []);
|
||||
/** State of the current view being processed. */
|
||||
let currentView: LView;
|
||||
// The initialization has to be after the `let`, otherwise `createLView` can't see `let`.
|
||||
currentView = createLView(null !, null !, []);
|
||||
|
||||
let currentQuery: QueryState|null;
|
||||
let currentQuery: LQuery|null;
|
||||
|
||||
/**
|
||||
* This property gets set before entering a template.
|
||||
|
@ -141,41 +139,41 @@ let viewHookStartIndex: number|null;
|
|||
* is entered we have to store the state for later, and when the view is
|
||||
* exited the state has to be restored
|
||||
*
|
||||
* @param newViewState New state to become active
|
||||
* @param newView New state to become active
|
||||
* @param host Element to which the View is a child of
|
||||
* @returns the previous state;
|
||||
*/
|
||||
export function enterView(newViewState: ViewState, host: LElement | LView | null): ViewState {
|
||||
const oldViewState = currentView;
|
||||
data = newViewState.data;
|
||||
bindingIndex = newViewState.bindingStartIndex || 0;
|
||||
ngStaticData = newViewState.ngStaticData;
|
||||
creationMode = newViewState.creationMode;
|
||||
export function enterView(newView: LView, host: LElementNode | LViewNode | null): LView {
|
||||
const oldView = currentView;
|
||||
data = newView.data;
|
||||
bindingIndex = newView.bindingStartIndex || 0;
|
||||
ngStaticData = newView.ngStaticData;
|
||||
creationMode = newView.creationMode;
|
||||
|
||||
viewHookStartIndex = newViewState.viewHookStartIndex;
|
||||
cleanup = newViewState.cleanup;
|
||||
renderer = newViewState.renderer;
|
||||
viewHookStartIndex = newView.viewHookStartIndex;
|
||||
cleanup = newView.cleanup;
|
||||
renderer = newView.renderer;
|
||||
|
||||
if (host != null) {
|
||||
previousOrParentNode = host;
|
||||
isParent = true;
|
||||
}
|
||||
|
||||
currentView = newViewState;
|
||||
return oldViewState !;
|
||||
currentView = newView;
|
||||
return oldView !;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used in lieu of enterView to make it clear when we are exiting a child view. This makes
|
||||
* the direction of traversal (up or down the view tree) a bit clearer.
|
||||
*/
|
||||
export function leaveView(newViewState: ViewState): void {
|
||||
export function leaveView(newView: LView): void {
|
||||
executeViewHooks();
|
||||
enterView(newViewState, null);
|
||||
enterView(newView, null);
|
||||
}
|
||||
|
||||
export function createViewState(
|
||||
viewId: number, renderer: Renderer3, ngStaticData: NgStaticData): ViewState {
|
||||
export function createLView(
|
||||
viewId: number, renderer: Renderer3, ngStaticData: NgStaticData): LView {
|
||||
const newView = {
|
||||
parent: currentView,
|
||||
id: viewId, // -1 for component views
|
||||
|
@ -201,25 +199,25 @@ export function createViewState(
|
|||
*/
|
||||
export function createLNode(
|
||||
index: number | null, type: LNodeFlags.Element, native: RElement | RText | null,
|
||||
viewState?: ViewState | null): LElement;
|
||||
lView?: LView | null): LElementNode;
|
||||
export function createLNode(
|
||||
index: null, type: LNodeFlags.View, native: null, viewState: ViewState): LView;
|
||||
index: null, type: LNodeFlags.View, native: null, lView: LView): LViewNode;
|
||||
export function createLNode(
|
||||
index: number, type: LNodeFlags.Container, native: RComment,
|
||||
containerState: ContainerState): LContainer;
|
||||
lContainer: LContainer): LContainerNode;
|
||||
export function createLNode(
|
||||
index: number, type: LNodeFlags.Projection, native: null,
|
||||
projectionState: ProjectionState): LProjection;
|
||||
lProjection: LProjection): LProjectionNode;
|
||||
export function createLNode(
|
||||
index: number | null, type: LNodeFlags, native: RText | RElement | RComment | null,
|
||||
state?: null | ViewState | ContainerState | ProjectionState): LElement<ext&LView&LContainer&
|
||||
LProjection {
|
||||
state?: null | LView | LContainer | LProjection): LElementNode<extNode&LViewNode&
|
||||
LContainerNode&LProjectionNode {
|
||||
const parent = isParent ? previousOrParentNode :
|
||||
previousOrParentNode && previousOrParentNode.parent as LNode;
|
||||
let query = (isParent ? currentQuery : previousOrParentNode && previousOrParentNode.query) ||
|
||||
parent && parent.query && parent.query.child();
|
||||
const isState = state != null;
|
||||
const node: LElement<ext&LView&LContainer&LProjection = {
|
||||
const node: LElementNode<extNode&LViewNode&LContainerNode&LProjectionNode = {
|
||||
flags: type,
|
||||
native: native as any,
|
||||
view: currentView,
|
||||
|
@ -229,14 +227,14 @@ export function createLNode(
|
|||
nodeInjector: parent ? parent.nodeInjector : null,
|
||||
data: isState ? state as any : null,
|
||||
query: query,
|
||||
staticData: null
|
||||
tNode: null
|
||||
};
|
||||
|
||||
if ((type & LNodeFlags.ViewOrElement) === LNodeFlags.ViewOrElement && isState) {
|
||||
// Bit of a hack to bust through the readonly because there is a circular dep between
|
||||
// ViewState and LNode.
|
||||
ngDevMode && assertEqual((state as ViewState).node, null, 'viewState.node');
|
||||
(state as ViewState as{node: LNode}).node = node;
|
||||
// LView and LNode.
|
||||
ngDevMode && assertEqual((state as LView).node, null, 'lView.node');
|
||||
(state as LView as{node: LNode}).node = node;
|
||||
}
|
||||
if (index != null) {
|
||||
// We are Element or Container
|
||||
|
@ -247,7 +245,7 @@ export function createLNode(
|
|||
if (index >= ngStaticData.length) {
|
||||
ngStaticData[index] = null;
|
||||
} else {
|
||||
node.staticData = ngStaticData[index] as LNodeStatic;
|
||||
node.tNode = ngStaticData[index] as TNode;
|
||||
}
|
||||
|
||||
// Now link ourselves into the tree.
|
||||
|
@ -292,13 +290,13 @@ function resetApplicationState() {
|
|||
*/
|
||||
export function renderTemplate<T>(
|
||||
hostNode: RElement, template: ComponentTemplate<T>, context: T,
|
||||
providedRendererFactory: RendererFactory3, host: LElement | null): LElement {
|
||||
providedRendererFactory: RendererFactory3, host: LElementNode | null): LElementNode {
|
||||
if (host == null) {
|
||||
resetApplicationState();
|
||||
rendererFactory = providedRendererFactory;
|
||||
host = createLNode(
|
||||
null, LNodeFlags.Element, hostNode,
|
||||
createViewState(-1, providedRendererFactory.createRenderer(null, null), []));
|
||||
createLView(-1, providedRendererFactory.createRenderer(null, null), []));
|
||||
}
|
||||
const hostView = host.data !;
|
||||
ngDevMode && assertNotEqual(hostView, null, 'hostView');
|
||||
|
@ -308,8 +306,8 @@ export function renderTemplate<T>(
|
|||
}
|
||||
|
||||
export function renderComponentOrTemplate<T>(
|
||||
node: LElement, viewState: ViewState, componentOrContext: T, template?: ComponentTemplate<T>) {
|
||||
const oldView = enterView(viewState, node);
|
||||
node: LElementNode, lView: LView, componentOrContext: T, template?: ComponentTemplate<T>) {
|
||||
const oldView = enterView(lView, node);
|
||||
try {
|
||||
if (rendererFactory.begin) {
|
||||
rendererFactory.begin();
|
||||
|
@ -326,14 +324,14 @@ export function renderComponentOrTemplate<T>(
|
|||
if (rendererFactory.end) {
|
||||
rendererFactory.end();
|
||||
}
|
||||
viewState.creationMode = false;
|
||||
lView.creationMode = false;
|
||||
leaveView(oldView);
|
||||
}
|
||||
}
|
||||
|
||||
export function getOrCreateNodeInjector(): LNodeInjector {
|
||||
export function getOrCreateNodeInjector(): LInjector {
|
||||
ngDevMode && assertPreviousIsParent();
|
||||
return getOrCreateNodeInjectorForNode(previousOrParentNode as LElement | LContainer);
|
||||
return getOrCreateNodeInjectorForNode(previousOrParentNode as LElementNode | LContainerNode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -420,13 +418,13 @@ export function injectViewContainerRef(): ViewContainerRef {
|
|||
export function elementStart(
|
||||
index: number, nameOrComponentDef?: string | ComponentDef<any>, attrs?: string[] | null,
|
||||
localName?: string): RElement {
|
||||
let node: LElement;
|
||||
let node: LElementNode;
|
||||
let native: RElement;
|
||||
|
||||
if (nameOrComponentDef == null) {
|
||||
// native node retrieval - used for exporting elements as tpl local variables (<div #foo>)
|
||||
const node = data[index] !;
|
||||
native = node && (node as LElement).native;
|
||||
native = node && (node as LElementNode).native;
|
||||
} else {
|
||||
ngDevMode && assertEqual(currentView.bindingStartIndex, null, 'bindingStartIndex');
|
||||
const isHostElement = typeof nameOrComponentDef !== 'string';
|
||||
|
@ -438,10 +436,10 @@ export function elementStart(
|
|||
} else {
|
||||
native = renderer.createElement(name);
|
||||
|
||||
let componentView: ViewState|null = null;
|
||||
let componentView: LView|null = null;
|
||||
if (isHostElement) {
|
||||
const ngStaticData = getTemplateStatic((nameOrComponentDef as ComponentDef<any>).template);
|
||||
componentView = addToViewTree(createViewState(
|
||||
componentView = addToViewTree(createLView(
|
||||
-1, rendererFactory.createRenderer(
|
||||
native, (nameOrComponentDef as ComponentDef<any>).rendererType),
|
||||
ngStaticData));
|
||||
|
@ -451,10 +449,10 @@ export function elementStart(
|
|||
// accessed through their containers because they may be removed / re-added later.
|
||||
node = createLNode(index, LNodeFlags.Element, native, componentView);
|
||||
|
||||
if (node.staticData == null) {
|
||||
if (node.tNode == null) {
|
||||
ngDevMode && assertDataInRange(index - 1);
|
||||
node.staticData = ngStaticData[index] =
|
||||
createNodeStatic(name, attrs || null, null, localName || null);
|
||||
node.tNode = ngStaticData[index] =
|
||||
createTNode(name, attrs || null, null, localName || null);
|
||||
}
|
||||
|
||||
if (attrs) setUpAttributes(native, attrs);
|
||||
|
@ -523,7 +521,7 @@ export function locateHostElement(
|
|||
export function hostElement(rNode: RElement | null, def: ComponentDef<any>) {
|
||||
resetApplicationState();
|
||||
createLNode(
|
||||
0, LNodeFlags.Element, rNode, createViewState(-1, renderer, getTemplateStatic(def.template)));
|
||||
0, LNodeFlags.Element, rNode, createLView(-1, renderer, getTemplateStatic(def.template)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -552,15 +550,15 @@ export function listener(eventName: string, listener: EventListener, useCapture
|
|||
(cleanup || (cleanup = currentView.cleanup = [])).push(eventName, native, listener, useCapture);
|
||||
}
|
||||
|
||||
let staticData: LNodeStatic|null = node.staticData !;
|
||||
if (staticData.outputs === undefined) {
|
||||
// if we create LNodeStatic here, inputs must be undefined so we know they still need to be
|
||||
let tNode: TNode|null = node.tNode !;
|
||||
if (tNode.outputs === undefined) {
|
||||
// if we create TNode here, inputs must be undefined so we know they still need to be
|
||||
// checked
|
||||
staticData.outputs = null;
|
||||
staticData = generatePropertyAliases(node.flags, staticData);
|
||||
tNode.outputs = null;
|
||||
tNode = generatePropertyAliases(node.flags, tNode);
|
||||
}
|
||||
|
||||
const outputs = staticData.outputs;
|
||||
const outputs = tNode.outputs;
|
||||
let outputData: (number | string)[]|undefined;
|
||||
if (outputs && (outputData = outputs[eventName])) {
|
||||
createOutput(outputData, listener);
|
||||
|
@ -602,7 +600,7 @@ export function elementEnd() {
|
|||
*/
|
||||
export function elementAttribute(index: number, attrName: string, value: any): void {
|
||||
if (value !== NO_CHANGE) {
|
||||
const element = data[index] as LElement;
|
||||
const element = data[index] as LElementNode;
|
||||
if (value == null) {
|
||||
(renderer as ProceduralRenderer3).removeAttribute ?
|
||||
(renderer as ProceduralRenderer3).removeAttribute(element.native, attrName) :
|
||||
|
@ -631,18 +629,18 @@ export function elementAttribute(index: number, attrName: string, value: any): v
|
|||
|
||||
export function elementProperty<T>(index: number, propName: string, value: T | NO_CHANGE): void {
|
||||
if (value === NO_CHANGE) return;
|
||||
const node = data[index] as LElement;
|
||||
const node = data[index] as LElementNode;
|
||||
|
||||
let staticData: LNodeStatic|null = node.staticData !;
|
||||
// if staticData.inputs is undefined, a listener has created output staticData, but inputs haven't
|
||||
let tNode: TNode|null = node.tNode !;
|
||||
// if tNode.inputs is undefined, a listener has created outputs, but inputs haven't
|
||||
// yet been checked
|
||||
if (staticData.inputs === undefined) {
|
||||
if (tNode.inputs === undefined) {
|
||||
// mark inputs as checked
|
||||
staticData.inputs = null;
|
||||
staticData = generatePropertyAliases(node.flags, staticData, true);
|
||||
tNode.inputs = null;
|
||||
tNode = generatePropertyAliases(node.flags, tNode, true);
|
||||
}
|
||||
|
||||
const inputData = staticData.inputs;
|
||||
const inputData = tNode.inputs;
|
||||
let dataValue: PropertyAliasValue|null;
|
||||
if (inputData && (dataValue = inputData[propName])) {
|
||||
setInputsForProperty(dataValue, value);
|
||||
|
@ -656,16 +654,16 @@ export function elementProperty<T>(index: number, propName: string, value: T | N
|
|||
}
|
||||
|
||||
/**
|
||||
* Constructs a LNodeStatic object from the arguments.
|
||||
* Constructs a TNode object from the arguments.
|
||||
*
|
||||
* @param tagName
|
||||
* @param attrs
|
||||
* @param containerStatic
|
||||
* @returns the LNodeStatic object
|
||||
* @returns the TNode object
|
||||
*/
|
||||
function createNodeStatic(
|
||||
tagName: string | null, attrs: string[] | null,
|
||||
containerStatic: (LNodeStatic | null)[][] | null, localName: string | null): LNodeStatic {
|
||||
function createTNode(
|
||||
tagName: string | null, attrs: string[] | null, containerStatic: (TNode | null)[][] | null,
|
||||
localName: string | null): TNode {
|
||||
return {
|
||||
tagName: tagName,
|
||||
attrs: attrs,
|
||||
|
@ -695,8 +693,7 @@ function setInputsForProperty(inputs: (number | string)[], value: any): void {
|
|||
*
|
||||
* @param index Index where data should be stored in ngStaticData
|
||||
*/
|
||||
function generatePropertyAliases(
|
||||
flags: number, data: LNodeStatic, isInputData = false): LNodeStatic {
|
||||
function generatePropertyAliases(flags: number, tNode: TNode, isInputData = false): TNode {
|
||||
const start = flags >> LNodeFlags.INDX_SHIFT;
|
||||
const size = (flags & LNodeFlags.SIZE_MASK) >> LNodeFlags.SIZE_SHIFT;
|
||||
|
||||
|
@ -707,15 +704,16 @@ function generatePropertyAliases(
|
|||
for (let publicName in propertyAliasMap) {
|
||||
if (propertyAliasMap.hasOwnProperty(publicName)) {
|
||||
const internalName = propertyAliasMap[publicName];
|
||||
const staticDirData: PropertyAliases = isInputData ? (data.inputs || (data.inputs = {})) :
|
||||
(data.outputs || (data.outputs = {}));
|
||||
const staticDirData: PropertyAliases = isInputData ?
|
||||
(tNode.inputs || (tNode.inputs = {})) :
|
||||
(tNode.outputs || (tNode.outputs = {}));
|
||||
const hasProperty: boolean = staticDirData.hasOwnProperty(publicName);
|
||||
hasProperty ? staticDirData[publicName].push(i, internalName) :
|
||||
(staticDirData[publicName] = [i, internalName]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return data;
|
||||
return tNode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -730,7 +728,7 @@ function generatePropertyAliases(
|
|||
*/
|
||||
export function elementClass<T>(index: number, className: string, value: T | NO_CHANGE): void {
|
||||
if (value !== NO_CHANGE) {
|
||||
const lElement = data[index] as LElement;
|
||||
const lElement = data[index] as LElementNode;
|
||||
if (value) {
|
||||
(renderer as ProceduralRenderer3).addClass ?
|
||||
(renderer as ProceduralRenderer3).addClass(lElement.native, className) :
|
||||
|
@ -756,7 +754,7 @@ export function elementClass<T>(index: number, className: string, value: T | NO_
|
|||
export function elementStyle<T>(
|
||||
index: number, styleName: string, value: T | NO_CHANGE, suffix?: string): void {
|
||||
if (value !== NO_CHANGE) {
|
||||
const lElement = data[index] as LElement;
|
||||
const lElement = data[index] as LElementNode;
|
||||
if (value == null) {
|
||||
(renderer as ProceduralRenderer3).removeStyle ?
|
||||
(renderer as ProceduralRenderer3)
|
||||
|
@ -809,7 +807,7 @@ export function text(index: number, value?: any): void {
|
|||
*/
|
||||
export function textBinding<T>(index: number, value: T | NO_CHANGE): void {
|
||||
// TODO(misko): I don't think index < nodes.length check is needed here.
|
||||
let existingNode = index < data.length && data[index] as LText;
|
||||
let existingNode = index < data.length && data[index] as LTextNode;
|
||||
if (existingNode && existingNode.native) {
|
||||
// If DOM node exists and value changed, update textContent
|
||||
value !== NO_CHANGE &&
|
||||
|
@ -876,10 +874,9 @@ export function directive<T>(
|
|||
if (index >= ngStaticData.length) {
|
||||
ngStaticData[index] = directiveDef !;
|
||||
if (localName) {
|
||||
ngDevMode &&
|
||||
assertNotNull(previousOrParentNode.staticData, 'previousOrParentNode.staticData');
|
||||
const nodeStaticData = previousOrParentNode !.staticData !;
|
||||
(nodeStaticData.localNames || (nodeStaticData.localNames = [])).push(localName, index);
|
||||
ngDevMode && assertNotNull(previousOrParentNode.tNode, 'previousOrParentNode.staticData');
|
||||
const tNode = previousOrParentNode !.tNode !;
|
||||
(tNode.localNames || (tNode.localNames = [])).push(localName, index);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -888,9 +885,9 @@ export function directive<T>(
|
|||
diPublic(directiveDef !);
|
||||
}
|
||||
|
||||
const staticData: LNodeStatic|null = previousOrParentNode.staticData !;
|
||||
if (staticData && staticData.attrs) {
|
||||
setInputsFromAttrs<T>(instance, directiveDef !.inputs, staticData);
|
||||
const tNode: TNode|null = previousOrParentNode.tNode !;
|
||||
if (tNode && tNode.attrs) {
|
||||
setInputsFromAttrs<T>(instance, directiveDef !.inputs, tNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -902,16 +899,15 @@ export function directive<T>(
|
|||
*
|
||||
* @param instance Instance of the directive on which to set the initial inputs
|
||||
* @param inputs The list of inputs from the directive def
|
||||
* @param staticData The static data for this node
|
||||
* @param tNode The static data for this node
|
||||
*/
|
||||
function setInputsFromAttrs<T>(
|
||||
instance: T, inputs: {[key: string]: string}, staticData: LNodeStatic): void {
|
||||
function setInputsFromAttrs<T>(instance: T, inputs: {[key: string]: string}, tNode: TNode): void {
|
||||
const directiveIndex =
|
||||
((previousOrParentNode.flags & LNodeFlags.SIZE_MASK) >> LNodeFlags.SIZE_SHIFT) - 1;
|
||||
|
||||
let initialInputData = staticData.initialInputs as InitialInputData | undefined;
|
||||
let initialInputData = tNode.initialInputs as InitialInputData | undefined;
|
||||
if (initialInputData === undefined || directiveIndex >= initialInputData.length) {
|
||||
initialInputData = generateInitialInputs(directiveIndex, inputs, staticData);
|
||||
initialInputData = generateInitialInputs(directiveIndex, inputs, tNode);
|
||||
}
|
||||
|
||||
const initialInputs: InitialInputs|null = initialInputData[directiveIndex];
|
||||
|
@ -935,16 +931,14 @@ function setInputsFromAttrs<T>(
|
|||
*
|
||||
* @param directiveIndex Index to store the initial input data
|
||||
* @param inputs The list of inputs from the directive def
|
||||
* @param staticData The static data on this node
|
||||
* @param tNode The static data on this node
|
||||
*/
|
||||
function generateInitialInputs(
|
||||
directiveIndex: number, inputs: {[key: string]: string},
|
||||
staticData: LNodeStatic): InitialInputData {
|
||||
const initialInputData: InitialInputData =
|
||||
staticData.initialInputs || (staticData.initialInputs = []);
|
||||
directiveIndex: number, inputs: {[key: string]: string}, tNode: TNode): InitialInputData {
|
||||
const initialInputData: InitialInputData = tNode.initialInputs || (tNode.initialInputs = []);
|
||||
initialInputData[directiveIndex] = null;
|
||||
|
||||
const attrs = staticData.attrs !;
|
||||
const attrs = tNode.attrs !;
|
||||
for (let i = 0; i < attrs.length; i += 2) {
|
||||
const attrName = attrs[i];
|
||||
const minifiedInputName = inputs[attrName];
|
||||
|
@ -1033,9 +1027,9 @@ export function executeViewHooks(): void {
|
|||
//////////////////////////
|
||||
|
||||
/**
|
||||
* Creates an LContainer.
|
||||
* Creates an LContainerNode.
|
||||
*
|
||||
* Only `LView`s can go into `LContainer`.
|
||||
* Only `LViewNodes` can go into `LContainerNodes`.
|
||||
*
|
||||
* @param index The index of the container in the data array
|
||||
* @param template Optional inline template
|
||||
|
@ -1051,17 +1045,17 @@ export function containerStart(
|
|||
// will need to be added through insertView() when its parent view is being inserted.
|
||||
// For now, it is marked "headless" so we know to append its views later.
|
||||
let comment = renderer.createComment(ngDevMode ? 'container' : '');
|
||||
let renderParent: LElement|null = null;
|
||||
let renderParent: LElementNode|null = null;
|
||||
const currentParent = isParent ? previousOrParentNode : previousOrParentNode.parent !;
|
||||
ngDevMode && assertNotEqual(currentParent, null, 'currentParent');
|
||||
if (appendChild(currentParent, comment, currentView)) {
|
||||
// we are adding to an Element which is either:
|
||||
// - Not a component (will not be re-projected, just added)
|
||||
// - View of the Component
|
||||
renderParent = currentParent as LElement;
|
||||
renderParent = currentParent as LElementNode;
|
||||
}
|
||||
|
||||
const node = createLNode(index, LNodeFlags.Container, comment, <ContainerState>{
|
||||
const node = createLNode(index, LNodeFlags.Container, comment, <LContainer>{
|
||||
views: [],
|
||||
nextIndex: 0, renderParent,
|
||||
template: template == null ? null : template,
|
||||
|
@ -1069,9 +1063,9 @@ export function containerStart(
|
|||
parent: currentView
|
||||
});
|
||||
|
||||
if (node.staticData == null) {
|
||||
node.staticData = ngStaticData[index] =
|
||||
createNodeStatic(tagName || null, attrs || null, [], localName || null);
|
||||
if (node.tNode == null) {
|
||||
node.tNode = ngStaticData[index] =
|
||||
createTNode(tagName || null, attrs || null, [], localName || null);
|
||||
}
|
||||
|
||||
// Containers are added to the current view tree instead of their embedded views
|
||||
|
@ -1101,13 +1095,13 @@ export function containerRefreshStart(index: number): void {
|
|||
previousOrParentNode = data[index] as LNode;
|
||||
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Container);
|
||||
isParent = true;
|
||||
(previousOrParentNode as LContainer).data.nextIndex = 0;
|
||||
(previousOrParentNode as LContainerNode).data.nextIndex = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks the end of the LContainer.
|
||||
* Marks the end of the LContainerNode.
|
||||
*
|
||||
* Marking the end of ViewContainer is the time when to child Views get inserted or removed.
|
||||
* Marking the end of LContainerNode is the time when to child Views get inserted or removed.
|
||||
*/
|
||||
export function containerRefreshEnd(): void {
|
||||
if (isParent) {
|
||||
|
@ -1118,7 +1112,7 @@ export function containerRefreshEnd(): void {
|
|||
previousOrParentNode = previousOrParentNode.parent !;
|
||||
}
|
||||
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.Container);
|
||||
const container = previousOrParentNode as LContainer;
|
||||
const container = previousOrParentNode as LContainerNode;
|
||||
ngDevMode && assertNodeType(container, LNodeFlags.Container);
|
||||
const nextIndex = container.data.nextIndex;
|
||||
while (nextIndex < container.data.views.length) {
|
||||
|
@ -1128,32 +1122,32 @@ export function containerRefreshEnd(): void {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates an LView.
|
||||
* Creates an LViewNode.
|
||||
*
|
||||
* @param viewBlockId The ID of this view
|
||||
* @return Whether or not this view is in creation mode
|
||||
*/
|
||||
export function viewStart(viewBlockId: number): boolean {
|
||||
const container = (isParent ? previousOrParentNode : previousOrParentNode.parent !) as LContainer;
|
||||
const container =
|
||||
(isParent ? previousOrParentNode : previousOrParentNode.parent !) as LContainerNode;
|
||||
ngDevMode && assertNodeType(container, LNodeFlags.Container);
|
||||
const containerState = container.data;
|
||||
const views = containerState.views;
|
||||
const lContainer = container.data;
|
||||
const views = lContainer.views;
|
||||
|
||||
const existingView: LView|false =
|
||||
!creationMode && containerState.nextIndex < views.length && views[containerState.nextIndex];
|
||||
let viewUpdateMode = existingView && viewBlockId === (existingView as LView).data.id;
|
||||
const existingView: LViewNode|false =
|
||||
!creationMode && lContainer.nextIndex < views.length && views[lContainer.nextIndex];
|
||||
let viewUpdateMode = existingView && viewBlockId === (existingView as LViewNode).data.id;
|
||||
|
||||
if (viewUpdateMode) {
|
||||
previousOrParentNode = views[containerState.nextIndex++];
|
||||
previousOrParentNode = views[lContainer.nextIndex++];
|
||||
ngDevMode && assertNodeType(previousOrParentNode, LNodeFlags.View);
|
||||
isParent = true;
|
||||
enterView((existingView as LView).data, previousOrParentNode as LView);
|
||||
enterView((existingView as LViewNode).data, previousOrParentNode as LViewNode);
|
||||
} else {
|
||||
// When we create a new View, we always reset the state of the instructions.
|
||||
const newViewState =
|
||||
createViewState(viewBlockId, renderer, initViewStaticData(viewBlockId, container));
|
||||
enterView(newViewState, createLNode(null, LNodeFlags.View, null, newViewState));
|
||||
containerState.nextIndex++;
|
||||
// When we create a new LView, we always reset the state of the instructions.
|
||||
const newView = createLView(viewBlockId, renderer, initViewStaticData(viewBlockId, container));
|
||||
enterView(newView, createLNode(null, LNodeFlags.View, null, newView));
|
||||
lContainer.nextIndex++;
|
||||
}
|
||||
|
||||
return !viewUpdateMode;
|
||||
|
@ -1171,30 +1165,30 @@ export function viewStart(viewBlockId: number): boolean {
|
|||
* @param parent The parent container in which to look for the view's static data
|
||||
* @returns NgStaticData
|
||||
*/
|
||||
function initViewStaticData(viewIndex: number, parent: LContainer): NgStaticData {
|
||||
function initViewStaticData(viewIndex: number, parent: LContainerNode): NgStaticData {
|
||||
ngDevMode && assertNodeType(parent, LNodeFlags.Container);
|
||||
const containerStatic = (parent !.staticData as LContainerStatic).containerStatic;
|
||||
const containerStatic = (parent !.tNode as TContainerNode).containerStatic;
|
||||
if (viewIndex >= containerStatic.length || containerStatic[viewIndex] == null) {
|
||||
containerStatic[viewIndex] = [];
|
||||
}
|
||||
return containerStatic[viewIndex];
|
||||
}
|
||||
|
||||
/** Marks the end of the LView. */
|
||||
/** Marks the end of the LViewNode. */
|
||||
export function viewEnd(): void {
|
||||
isParent = false;
|
||||
const viewNode = previousOrParentNode = currentView.node as LView;
|
||||
const container = previousOrParentNode.parent as LContainer;
|
||||
const viewNode = previousOrParentNode = currentView.node as LViewNode;
|
||||
const container = previousOrParentNode.parent as LContainerNode;
|
||||
ngDevMode && assertNodeType(viewNode, LNodeFlags.View);
|
||||
ngDevMode && assertNodeType(container, LNodeFlags.Container);
|
||||
const containerState = container.data;
|
||||
const previousView = containerState.nextIndex <= containerState.views.length ?
|
||||
containerState.views[containerState.nextIndex - 1] as LView :
|
||||
const lContainer = container.data;
|
||||
const previousView = lContainer.nextIndex <= lContainer.views.length ?
|
||||
lContainer.views[lContainer.nextIndex - 1] as LViewNode :
|
||||
null;
|
||||
const viewIdChanged = previousView == null ? true : previousView.data.id !== viewNode.data.id;
|
||||
|
||||
if (viewIdChanged) {
|
||||
insertView(container, viewNode, containerState.nextIndex - 1);
|
||||
insertView(container, viewNode, lContainer.nextIndex - 1);
|
||||
currentView.creationMode = false;
|
||||
}
|
||||
leaveView(currentView !.parent !);
|
||||
|
@ -1217,7 +1211,7 @@ export const componentRefresh:
|
|||
void = function<T>(
|
||||
directiveIndex: number, elementIndex: number, template: ComponentTemplate<T>) {
|
||||
ngDevMode && assertDataInRange(elementIndex);
|
||||
const element = data ![elementIndex] as LElement;
|
||||
const element = data ![elementIndex] as LElementNode;
|
||||
ngDevMode && assertNodeType(element, LNodeFlags.Element);
|
||||
ngDevMode && assertNotEqual(element.data, null, 'isComponent');
|
||||
ngDevMode && assertDataInRange(directiveIndex);
|
||||
|
@ -1261,9 +1255,9 @@ export function projectionDef(selectors?: CssSelector[]): LNode[][] {
|
|||
// - elements, excluding text nodes;
|
||||
// - containers that have tagName and attributes associated.
|
||||
|
||||
if (componentChild.staticData) {
|
||||
if (componentChild.tNode) {
|
||||
for (let i = 0; i < selectors !.length; i++) {
|
||||
if (isNodeMatchingSelector(componentChild.staticData, selectors ![i])) {
|
||||
if (isNodeMatchingSelector(componentChild.tNode, selectors ![i])) {
|
||||
distributedNodes[i + 1].push(componentChild);
|
||||
break; // first matching selector "captures" a given node
|
||||
} else {
|
||||
|
@ -1275,7 +1269,7 @@ export function projectionDef(selectors?: CssSelector[]): LNode[][] {
|
|||
}
|
||||
|
||||
} else if ((componentChild.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.Projection) {
|
||||
// we don't descent into nodes to re-project (not trying to match selectors against nodes to
|
||||
// we don't descend into nodes to re-project (not trying to match selectors against nodes to
|
||||
// re-project)
|
||||
distributedNodes[0].push(componentChild);
|
||||
}
|
||||
|
@ -1294,7 +1288,7 @@ export function projectionDef(selectors?: CssSelector[]): LNode[][] {
|
|||
* @param selectorIndex - 0 means <ng-content> without any selector
|
||||
*/
|
||||
export function projection(nodeIndex: number, localIndex: number, selectorIndex: number = 0): void {
|
||||
const projectedNodes: ProjectionState = [];
|
||||
const projectedNodes: LProjection = [];
|
||||
const node = createLNode(nodeIndex, LNodeFlags.Projection, null, projectedNodes);
|
||||
isParent = false; // self closing
|
||||
const currentParent = node.parent;
|
||||
|
@ -1309,14 +1303,14 @@ export function projection(nodeIndex: number, localIndex: number, selectorIndex:
|
|||
for (let i = 0; i < nodesForSelector.length; i++) {
|
||||
const nodeToProject = nodesForSelector[i];
|
||||
if ((nodeToProject.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.Projection) {
|
||||
const previouslyProjectedNodes = (nodeToProject as LProjection).data;
|
||||
const previouslyProjectedNodes = (nodeToProject as LProjectionNode).data;
|
||||
for (let j = 0; j < previouslyProjectedNodes.length; j++) {
|
||||
processProjectedNode(
|
||||
projectedNodes, previouslyProjectedNodes[j], currentParent, currentView);
|
||||
}
|
||||
} else {
|
||||
processProjectedNode(
|
||||
projectedNodes, nodeToProject as LElement | LText | LContainer, currentParent,
|
||||
projectedNodes, nodeToProject as LElementNode | LTextNode | LContainerNode, currentParent,
|
||||
currentView);
|
||||
}
|
||||
}
|
||||
|
@ -1325,33 +1319,33 @@ export function projection(nodeIndex: number, localIndex: number, selectorIndex:
|
|||
/**
|
||||
* Given a current view, finds the nearest component's host (LElement).
|
||||
*
|
||||
* @param viewState ViewState for which we want a host element node
|
||||
* @param lView LView for which we want a host element node
|
||||
* @returns The host node
|
||||
*/
|
||||
function findComponentHost(viewState: ViewState): LElement {
|
||||
let viewRootLNode = viewState.node;
|
||||
function findComponentHost(lView: LView): LElementNode {
|
||||
let viewRootLNode = lView.node;
|
||||
while ((viewRootLNode.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.View) {
|
||||
ngDevMode && assertNotNull(viewState.parent, 'viewState.parent');
|
||||
viewState = viewState.parent !;
|
||||
viewRootLNode = viewState.node;
|
||||
ngDevMode && assertNotNull(lView.parent, 'lView.parent');
|
||||
lView = lView.parent !;
|
||||
viewRootLNode = lView.node;
|
||||
}
|
||||
|
||||
ngDevMode && assertNodeType(viewRootLNode, LNodeFlags.Element);
|
||||
ngDevMode && assertNotNull(viewRootLNode.data, 'node.data');
|
||||
|
||||
return viewRootLNode as LElement;
|
||||
return viewRootLNode as LElementNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a ViewState or a ContainerState to the end of the current view tree.
|
||||
* Adds a LView or a LContainer to the end of the current view tree.
|
||||
*
|
||||
* This structure will be used to traverse through nested views to remove listeners
|
||||
* and call onDestroy callbacks.
|
||||
*
|
||||
* @param state The ViewState or ContainerState to add to the view tree
|
||||
* @param state The LView or LContainer to add to the view tree
|
||||
* @returns The state passed in
|
||||
*/
|
||||
export function addToViewTree<T extends ViewState|ContainerState>(state: T): T {
|
||||
export function addToViewTree<T extends LView|LContainer>(state: T): T {
|
||||
currentView.tail ? (currentView.tail.next = state) : (currentView.child = state);
|
||||
currentView.tail = state;
|
||||
return state;
|
||||
|
@ -1849,7 +1843,7 @@ export function query<T>(
|
|||
read?: QueryReadType | Type<T>): QueryList<T> {
|
||||
ngDevMode && assertPreviousIsParent();
|
||||
const queryList = new QueryList<T>();
|
||||
const query = currentQuery || (currentQuery = new QueryState_());
|
||||
const query = currentQuery || (currentQuery = new LQuery_());
|
||||
query.track(queryList, predicate, descend, read);
|
||||
return queryList;
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ import {ViewContainerRef} from '../linker/view_container_ref';
|
|||
import {Type} from '../type';
|
||||
|
||||
import {ComponentTemplate, DirectiveDef} from './definition_interfaces';
|
||||
import {LNodeStatic} from './l_node_static';
|
||||
import {RComment, RElement, RText, Renderer3} from './renderer';
|
||||
import {TNode} from './t_node';
|
||||
|
||||
|
||||
|
||||
|
@ -100,13 +100,13 @@ export interface LNode {
|
|||
next: LNode|null;
|
||||
|
||||
/**
|
||||
* If regular LElement, then `data` will be null.
|
||||
* If LElement with component, then `data` contains ViewState.
|
||||
* If LView, then `data` contains the ViewState.
|
||||
* If LContainer, then `data` contains ContainerState.
|
||||
* If LProjection, then `data` contains ProjectionState.
|
||||
* If regular LElementNode, then `data` will be null.
|
||||
* If LElementNode with component, then `data` contains LView.
|
||||
* If LViewNode, then `data` contains the LView.
|
||||
* If LContainerNode, then `data` contains LContainer.
|
||||
* If LProjectionNode, then `data` contains LProjection.
|
||||
*/
|
||||
readonly data: ViewState|ContainerState|ProjectionState|null;
|
||||
readonly data: LView|LContainer|LProjection|null;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -114,70 +114,66 @@ export interface LNode {
|
|||
*
|
||||
* When the injector is walking up a tree, it needs access to the `directives` (part of view).
|
||||
*/
|
||||
readonly view: ViewState;
|
||||
readonly view: LView;
|
||||
|
||||
/** The injector associated with this node. Necessary for DI. */
|
||||
nodeInjector: LNodeInjector|null;
|
||||
nodeInjector: LInjector|null;
|
||||
|
||||
/**
|
||||
* Optional `QueryState` used for tracking queries.
|
||||
*
|
||||
* If present the node creation/updates are reported to the `QueryState`.
|
||||
*/
|
||||
query: QueryState|null;
|
||||
query: LQuery|null;
|
||||
|
||||
/**
|
||||
* Pointer to the corresponding LNodeStatic object, which stores static
|
||||
* Pointer to the corresponding TNode object, which stores static
|
||||
* data about this node.
|
||||
*/
|
||||
staticData: LNodeStatic|null;
|
||||
tNode: TNode|null;
|
||||
}
|
||||
|
||||
|
||||
/** LNode representing an element. */
|
||||
export interface LElement extends LNode {
|
||||
export interface LElementNode extends LNode {
|
||||
/** The DOM element associated with this node. */
|
||||
readonly native: RElement;
|
||||
|
||||
child: LContainer|LElement|LText|LProjection|null;
|
||||
next: LContainer|LElement|LText|LProjection|null;
|
||||
child: LContainerNode|LElementNode|LTextNode|LProjectionNode|null;
|
||||
next: LContainerNode|LElementNode|LTextNode|LProjectionNode|null;
|
||||
|
||||
/** If Component than data has ViewState (light DOM) */
|
||||
readonly data: ViewState|null;
|
||||
/** If Component then data has LView (light DOM) */
|
||||
readonly data: LView|null;
|
||||
|
||||
/** LElement nodes can be inside other LElement nodes or inside LViews. */
|
||||
readonly parent: LElement|LView;
|
||||
/** LElementNodes can be inside other LElementNodes or inside LViewNodes. */
|
||||
readonly parent: LElementNode|LViewNode;
|
||||
}
|
||||
|
||||
/** LNode representing a #text node. */
|
||||
export interface LText extends LNode {
|
||||
export interface LTextNode extends LNode {
|
||||
/** The text node associated with this node. */
|
||||
native: RText;
|
||||
child: null;
|
||||
next: LContainer|LElement|LText|LProjection|null;
|
||||
next: LContainerNode|LElementNode|LTextNode|LProjectionNode|null;
|
||||
|
||||
/** LText nodes can be inside LElement nodes or inside LViews. */
|
||||
readonly parent: LElement|LView;
|
||||
/** LTextNodes can be inside LElementNodes or inside LViewNodes. */
|
||||
readonly parent: LElementNode|LViewNode;
|
||||
readonly data: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract node which contains root nodes of a view.
|
||||
*/
|
||||
export interface LView extends LNode {
|
||||
/** Abstract node which contains root nodes of a view. */
|
||||
export interface LViewNode extends LNode {
|
||||
readonly native: null;
|
||||
child: LContainer|LElement|LText|LProjection|null;
|
||||
next: LView|null;
|
||||
child: LContainerNode|LElementNode|LTextNode|LProjectionNode|null;
|
||||
next: LViewNode|null;
|
||||
|
||||
/** LView nodes can only be added to LContainers. */
|
||||
readonly parent: LContainer|null;
|
||||
readonly data: ViewState;
|
||||
/** LViewNodes can only be added to LContainerNodes. */
|
||||
readonly parent: LContainerNode|null;
|
||||
readonly data: LView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract node container which contains other views.
|
||||
*/
|
||||
export interface LContainer extends LNode {
|
||||
/** Abstract node container which contains other views. */
|
||||
export interface LContainerNode extends LNode {
|
||||
/**
|
||||
* This comment node is appended to the container's parent element to mark where
|
||||
* in the DOM the container's child views should be added.
|
||||
|
@ -186,24 +182,24 @@ export interface LContainer extends LNode {
|
|||
* until the parent view is processed.
|
||||
*/
|
||||
readonly native: RComment;
|
||||
readonly data: ContainerState;
|
||||
readonly data: LContainer;
|
||||
child: null;
|
||||
next: LContainer|LElement|LText|LProjection|null;
|
||||
next: LContainerNode|LElementNode|LTextNode|LProjectionNode|null;
|
||||
|
||||
/** Containers can be added to elements or views. */
|
||||
readonly parent: LElement|LView|null;
|
||||
readonly parent: LElementNode|LViewNode|null;
|
||||
}
|
||||
|
||||
|
||||
export interface LProjection extends LNode {
|
||||
export interface LProjectionNode extends LNode {
|
||||
readonly native: null;
|
||||
child: null;
|
||||
next: LContainer|LElement|LText|LProjection|null;
|
||||
next: LContainerNode|LElementNode|LTextNode|LProjectionNode|null;
|
||||
|
||||
readonly data: ProjectionState;
|
||||
readonly data: LProjection;
|
||||
|
||||
/** Projections can be added to elements or views. */
|
||||
readonly parent: LElement|LView;
|
||||
readonly parent: LElementNode|LViewNode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -220,12 +216,12 @@ export interface LProjection extends LNode {
|
|||
* shown here: https://jsperf.com/small-arrays-vs-linked-objects
|
||||
*/
|
||||
|
||||
export interface LNodeInjector {
|
||||
export interface LInjector {
|
||||
/**
|
||||
* We need to store a reference to the injector's parent so DI can keep looking up
|
||||
* the injector tree until it finds the dependency it's looking for.
|
||||
*/
|
||||
readonly parent: LNodeInjector|null;
|
||||
readonly parent: LInjector|null;
|
||||
|
||||
/**
|
||||
* Allows access to the directives array in that node's static data and to
|
||||
|
@ -233,7 +229,7 @@ export interface LNodeInjector {
|
|||
* for DI to retrieve a directive from the data array if injector indicates
|
||||
* it is there.
|
||||
*/
|
||||
readonly node: LElement|LContainer;
|
||||
readonly node: LElementNode|LContainerNode;
|
||||
|
||||
/**
|
||||
* The following bloom filter determines whether a directive is available
|
||||
|
@ -276,16 +272,16 @@ export interface LNodeInjector {
|
|||
}
|
||||
|
||||
/**
|
||||
* `ViewState` stores all of the information needed to process the instructions as
|
||||
* `LView` stores all of the information needed to process the instructions as
|
||||
* they are invoked from the template. Each embedded view and component view has its
|
||||
* own `ViewState`. When processing a particular view, we set the `currentView` to that
|
||||
* `ViewState`. When that view is done processing, the `currentView` is set back to
|
||||
* whatever the original `currentView` was before(the parent `ViewState`).
|
||||
* own `LView`. When processing a particular view, we set the `currentView` to that
|
||||
* `LView`. When that view is done processing, the `currentView` is set back to
|
||||
* whatever the original `currentView` was before(the parent `LView`).
|
||||
*
|
||||
* Keeping separate state for each view facilities view insertion / deletion, so we
|
||||
* don't have to edit the data array based on which views are present.
|
||||
*/
|
||||
export interface ViewState {
|
||||
export interface LView {
|
||||
/**
|
||||
* Whether or not the view is in creationMode.
|
||||
*
|
||||
|
@ -301,20 +297,20 @@ export interface ViewState {
|
|||
|
||||
/**
|
||||
* The parent view is needed when we exit the view and must restore the previous
|
||||
* `ViewState`. Without this, the render method would have to keep a stack of
|
||||
* `LView`. Without this, the render method would have to keep a stack of
|
||||
* views as it is recursively rendering templates.
|
||||
*/
|
||||
readonly parent: ViewState|null;
|
||||
readonly parent: LView|null;
|
||||
|
||||
/**
|
||||
* Pointer to the `LView` or `LElement` node which represents the root of the view.
|
||||
* Pointer to the `LViewNode` or `LElementNode` which represents the root of the view.
|
||||
*
|
||||
* If `LView`, this is an embedded view of a container. We need this to be able to
|
||||
* efficiently find the `LView` when inserting the view into an anchor.
|
||||
* If `LViewNode`, this is an embedded view of a container. We need this to be able to
|
||||
* efficiently find the `LViewNode` when inserting the view into an anchor.
|
||||
*
|
||||
* If `LElement`, this is the ViewState of a component.
|
||||
* If `LElementNode`, this is the LView of a component.
|
||||
*/
|
||||
readonly node: LView|LElement;
|
||||
readonly node: LViewNode|LElementNode;
|
||||
|
||||
/**
|
||||
* ID to determine whether this view is the same as the previous view
|
||||
|
@ -323,9 +319,7 @@ export interface ViewState {
|
|||
*/
|
||||
readonly id: number;
|
||||
|
||||
/**
|
||||
* Renderer to be used for this view.
|
||||
*/
|
||||
/** Renderer to be used for this view. */
|
||||
readonly renderer: Renderer3;
|
||||
|
||||
/**
|
||||
|
@ -356,33 +350,33 @@ export interface ViewState {
|
|||
cleanup: any[]|null;
|
||||
|
||||
/**
|
||||
* The first ViewState or ContainerState beneath this ViewState in the hierarchy.
|
||||
* The first LView or LContainer beneath this LView in the hierarchy.
|
||||
*
|
||||
* Necessary to store this so views can traverse through their nested views
|
||||
* to remove listeners and call onDestroy callbacks.
|
||||
*
|
||||
* For embedded views, we store the ContainerState rather than the first ViewState
|
||||
* For embedded views, we store the LContainer rather than the first ViewState
|
||||
* to avoid managing splicing when views are added/removed.
|
||||
*/
|
||||
child: ViewState|ContainerState|null;
|
||||
child: LView|LContainer|null;
|
||||
|
||||
/**
|
||||
* The last ViewState or ContainerState beneath this ViewState in the hierarchy.
|
||||
* The last LView or LContainer beneath this LView in the hierarchy.
|
||||
*
|
||||
* The tail allows us to quickly add a new state to the end of the view list
|
||||
* without having to propagate starting from the first child.
|
||||
*/
|
||||
tail: ViewState|ContainerState|null;
|
||||
tail: LView|LContainer|null;
|
||||
|
||||
/**
|
||||
* The next sibling ViewState or ContainerState.
|
||||
* The next sibling LView or LContainer.
|
||||
*
|
||||
* Allows us to propagate between sibling view states that aren't in the same
|
||||
* container. Embedded views already have a node.next, but it is only set for
|
||||
* views in the same container. We need a way to link component views and views
|
||||
* across containers as well.
|
||||
*/
|
||||
next: ViewState|ContainerState|null;
|
||||
next: LView|LContainer|null;
|
||||
|
||||
/**
|
||||
* This array stores all element/text/container nodes created inside this view
|
||||
|
@ -406,12 +400,12 @@ export interface ViewState {
|
|||
* can easily walk up the node tree in DI and get the ngStaticData array associated
|
||||
* with a node (where the directive defs are stored).
|
||||
*/
|
||||
ngStaticData: (LNodeStatic|DirectiveDef<any>|null)[];
|
||||
ngStaticData: (TNode|DirectiveDef<any>|null)[];
|
||||
}
|
||||
|
||||
|
||||
/** The state associated with an LContainer */
|
||||
export interface ContainerState {
|
||||
export interface LContainer {
|
||||
/**
|
||||
* The next active index in the views array to read or write to. This helps us
|
||||
* keep track of where we are in the views array.
|
||||
|
@ -422,13 +416,13 @@ export interface ContainerState {
|
|||
* This allows us to jump from a container to a sibling container or
|
||||
* component view with the same parent, so we can remove listeners efficiently.
|
||||
*/
|
||||
next: ViewState|ContainerState|null;
|
||||
next: LView|LContainer|null;
|
||||
|
||||
/**
|
||||
* Access to the parent view is necessary so we can propagate back
|
||||
* up from inside a container to parent.next.
|
||||
*/
|
||||
parent: ViewState|null;
|
||||
parent: LView|null;
|
||||
|
||||
/**
|
||||
* A list of the container's currently active child views. Views will be inserted
|
||||
|
@ -437,29 +431,29 @@ export interface ContainerState {
|
|||
* (and don't need to be re-added) and so we can remove views from the DOM when they
|
||||
* are no longer required.
|
||||
*/
|
||||
readonly views: LView[];
|
||||
readonly views: LViewNode[];
|
||||
|
||||
/**
|
||||
* Parent Element which will contain the location where all of the Views will be
|
||||
* inserted into to.
|
||||
*
|
||||
* If `renderParent` is `null` it is headless. This means that it is contained
|
||||
* in another `LView` which in turn is contained in another `LContainer` and therefore
|
||||
* it does not yet have its own parent.
|
||||
* in another `LViewNode` which in turn is contained in another `LContainerNode` and
|
||||
* therefore it does not yet have its own parent.
|
||||
*
|
||||
* If `renderParent` is not `null` then it may be:
|
||||
* - same as `LContainer.parent` in which case it is just a normal container.
|
||||
* - different from `LContainer.parent` in which case it has been re-projected.
|
||||
* In other words `LContainer.parent` is logical parent where as
|
||||
* `ContainerState.projectedParent` is render parent.
|
||||
* - same as `LContainerNode.parent` in which case it is just a normal container.
|
||||
* - different from `LContainerNode.parent` in which case it has been re-projected.
|
||||
* In other words `LContainerNode.parent` is logical parent where as
|
||||
* `LContainer.projectedParent` is render parent.
|
||||
*
|
||||
* When views are inserted into `LContainer` then `renderParent` is:
|
||||
* - `null`, we are in `LView` keep going up a hierarchy until actual
|
||||
* When views are inserted into `LContainerNode` then `renderParent` is:
|
||||
* - `null`, we are in `LViewNode` keep going up a hierarchy until actual
|
||||
* `renderParent` is found.
|
||||
* - not `null`, then use the `projectedParent.native` as the `RElement` to insert
|
||||
* `LView`s into.
|
||||
* `LViewNode`s into.
|
||||
*/
|
||||
renderParent: LElement|null;
|
||||
renderParent: LElementNode|null;
|
||||
|
||||
/**
|
||||
* The template extracted from the location of the Container.
|
||||
|
@ -469,35 +463,31 @@ export interface ContainerState {
|
|||
|
||||
|
||||
/** Interface necessary to work with view tree traversal */
|
||||
export interface ViewOrContainerState {
|
||||
next: ViewState|ContainerState|null;
|
||||
child?: ViewState|ContainerState|null;
|
||||
views?: LView[];
|
||||
parent: ViewState|null;
|
||||
export interface LViewOrLContainer {
|
||||
next: LView|LContainer|null;
|
||||
child?: LView|LContainer|null;
|
||||
views?: LViewNode[];
|
||||
parent: LView|null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A projection state is just an array of projected nodes.
|
||||
* An LProjection is just an array of projected nodes.
|
||||
*
|
||||
* It would be nice if we could not need an array, but since a projected node can be
|
||||
* re-projected, the same node can be part of more than one LProjection which makes
|
||||
* re-projected, the same node can be part of more than one LProjectionNode which makes
|
||||
* list approach not possible.
|
||||
*/
|
||||
export type ProjectionState = Array<LElement|LText|LContainer>;
|
||||
export type LProjection = Array<LElementNode|LTextNode|LContainerNode>;
|
||||
|
||||
/**
|
||||
* An enum representing possible values of the "read" option for queries.
|
||||
*/
|
||||
/** An enum representing possible values of the "read" option for queries. */
|
||||
export const enum QueryReadType {
|
||||
ElementRef = 0,
|
||||
ViewContainerRef = 1,
|
||||
TemplateRef = 2,
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for tracking queries (e.g. ViewChild, ContentChild).
|
||||
*/
|
||||
export interface QueryState {
|
||||
/** Used for tracking queries (e.g. ViewChild, ContentChild). */
|
||||
export interface LQuery {
|
||||
/**
|
||||
* Used to ask query if it should be cloned to the child element.
|
||||
*
|
||||
|
@ -505,22 +495,22 @@ export interface QueryState {
|
|||
* query for the child node. In case of shallow queries it returns
|
||||
* `null`.
|
||||
*/
|
||||
child(): QueryState|null;
|
||||
child(): LQuery|null;
|
||||
|
||||
/**
|
||||
* Notify `QueryState` that a `LNode` has been created.
|
||||
* Notify `LQuery` that a `LNode` has been created.
|
||||
*/
|
||||
addNode(node: LNode): void;
|
||||
|
||||
/**
|
||||
* Notify `QueryState` that a `LView` has been added to `LContainer`.
|
||||
* Notify `LQuery` that an `LViewNode` has been added to `LContainerNode`.
|
||||
*/
|
||||
insertView(container: LContainer, view: LView, insertIndex: number): void;
|
||||
insertView(container: LContainerNode, view: LViewNode, insertIndex: number): void;
|
||||
|
||||
/**
|
||||
* Notify `QueryState` that a `LView` has been removed from `LContainer`.
|
||||
* Notify `LQuery` that an `LViewNode` has been removed from `LContainerNode`.
|
||||
*/
|
||||
removeView(container: LContainer, view: LView, removeIndex: number): void;
|
||||
removeView(container: LContainerNode, view: LViewNode, removeIndex: number): void;
|
||||
|
||||
/**
|
||||
* Add additional `QueryList` to track.
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {assertNotNull} from './assert';
|
||||
import {ContainerState, LContainer, LElement, LNode, LNodeFlags, LProjection, LText, LView, ProjectionState, ViewOrContainerState, ViewState} from './interfaces';
|
||||
import {LContainer, LContainerNode, LElementNode, LNode, LNodeFlags, LProjection, LProjectionNode, LTextNode, LView, LViewNode, LViewOrLContainer} from './interfaces';
|
||||
import {assertNodeType} from './node_assert';
|
||||
import {ProceduralRenderer3, RComment, RElement, RNode, RText} from './renderer';
|
||||
|
||||
|
@ -22,15 +22,15 @@ import {ProceduralRenderer3, RComment, RElement, RNode, RText} from './renderer'
|
|||
* @param containerNode The container node whose parent must be found
|
||||
* @returns Closest DOM node above the container
|
||||
*/
|
||||
export function findNativeParent(containerNode: LContainer): RNode|null {
|
||||
let container: LContainer|null = containerNode;
|
||||
export function findNativeParent(containerNode: LContainerNode): RNode|null {
|
||||
let container: LContainerNode|null = containerNode;
|
||||
while (container) {
|
||||
ngDevMode && assertNodeType(container, LNodeFlags.Container);
|
||||
const renderParent = container.data.renderParent;
|
||||
if (renderParent !== null) {
|
||||
return renderParent.native;
|
||||
}
|
||||
const viewOrElement: LView|LElement = container.parent !;
|
||||
const viewOrElement: LViewNode|LElementNode = container.parent !;
|
||||
ngDevMode && assertNotNull(viewOrElement, 'container.parent');
|
||||
if ((viewOrElement.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.Element) {
|
||||
// we are an LElement, which means we are past the last LContainer.
|
||||
|
@ -38,7 +38,7 @@ export function findNativeParent(containerNode: LContainer): RNode|null {
|
|||
return null;
|
||||
}
|
||||
ngDevMode && assertNodeType(viewOrElement, LNodeFlags.View);
|
||||
container = (viewOrElement as LView).parent;
|
||||
container = (viewOrElement as LViewNode).parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -52,15 +52,15 @@ export function findNativeParent(containerNode: LContainer): RNode|null {
|
|||
* anchor is the marker.
|
||||
*
|
||||
* @param index The index of the view to check
|
||||
* @param state ContainerState of the parent container
|
||||
* @param lContainer parent LContainer
|
||||
* @param native Comment anchor for container
|
||||
* @returns The DOM element for which the view should insert elements
|
||||
*/
|
||||
function findBeforeNode(index: number, state: ContainerState, native: RNode): RNode {
|
||||
const views = state.views;
|
||||
function findBeforeNode(index: number, lContainer: LContainer, native: RNode): RNode {
|
||||
const views = lContainer.views;
|
||||
// Find the node to insert in front of
|
||||
return index + 1 < views.length ?
|
||||
(views[index + 1].child as LText | LElement | LContainer).native :
|
||||
(views[index + 1].child as LTextNode | LElementNode | LContainerNode).native :
|
||||
native;
|
||||
}
|
||||
|
||||
|
@ -77,11 +77,13 @@ function findBeforeNode(index: number, state: ContainerState, native: RNode): RN
|
|||
* @param beforeNode The node before which elements should be added, if insert mode
|
||||
*/
|
||||
export function addRemoveViewFromContainer(
|
||||
container: LContainer, rootNode: LView, insertMode: true, beforeNode: RNode | null): void;
|
||||
container: LContainerNode, rootNode: LViewNode, insertMode: true,
|
||||
beforeNode: RNode | null): void;
|
||||
export function addRemoveViewFromContainer(
|
||||
container: LContainer, rootNode: LView, insertMode: false): void;
|
||||
container: LContainerNode, rootNode: LViewNode, insertMode: false): void;
|
||||
export function addRemoveViewFromContainer(
|
||||
container: LContainer, rootNode: LView, insertMode: boolean, beforeNode?: RNode | null): void {
|
||||
container: LContainerNode, rootNode: LViewNode, insertMode: boolean,
|
||||
beforeNode?: RNode | null): void {
|
||||
ngDevMode && assertNodeType(container, LNodeFlags.Container);
|
||||
ngDevMode && assertNodeType(rootNode, LNodeFlags.View);
|
||||
const parent = findNativeParent(container);
|
||||
|
@ -105,7 +107,7 @@ export function addRemoveViewFromContainer(
|
|||
} else if (type === LNodeFlags.Container) {
|
||||
// if we get to a container, it must be a root node of a view because we are only
|
||||
// propagating down into child views / containers and not child elements
|
||||
const childContainerData: ContainerState = (node as LContainer).data;
|
||||
const childContainerData: LContainer = (node as LContainerNode).data;
|
||||
insertMode ? (isFnRenderer ?
|
||||
(renderer as ProceduralRenderer3)
|
||||
.appendChild !(parent as RElement, node.native !) :
|
||||
|
@ -116,9 +118,9 @@ export function addRemoveViewFromContainer(
|
|||
parent.removeChild(node.native !));
|
||||
nextNode = childContainerData.views.length ? childContainerData.views[0].child : null;
|
||||
} else if (type === LNodeFlags.Projection) {
|
||||
nextNode = (node as LProjection).data[0];
|
||||
nextNode = (node as LProjectionNode).data[0];
|
||||
} else {
|
||||
nextNode = (node as LView).child;
|
||||
nextNode = (node as LViewNode).child;
|
||||
}
|
||||
if (nextNode === null) {
|
||||
while (node && !node.next) {
|
||||
|
@ -146,31 +148,31 @@ export function addRemoveViewFromContainer(
|
|||
*
|
||||
* @param rootView The view to destroy
|
||||
*/
|
||||
export function destroyViewTree(rootView: ViewState): void {
|
||||
let viewOrContainerState: ViewOrContainerState|null = rootView;
|
||||
export function destroyViewTree(rootView: LView): void {
|
||||
let viewOrContainer: LViewOrLContainer|null = rootView;
|
||||
|
||||
while (viewOrContainerState) {
|
||||
let next: ViewOrContainerState|null = null;
|
||||
while (viewOrContainer) {
|
||||
let next: LViewOrLContainer|null = null;
|
||||
|
||||
if (viewOrContainerState.views && viewOrContainerState.views.length) {
|
||||
next = viewOrContainerState.views[0].data;
|
||||
} else if (viewOrContainerState.child) {
|
||||
next = viewOrContainerState.child;
|
||||
} else if (viewOrContainerState.next) {
|
||||
cleanUpView(viewOrContainerState as ViewState);
|
||||
next = viewOrContainerState.next;
|
||||
if (viewOrContainer.views && viewOrContainer.views.length) {
|
||||
next = viewOrContainer.views[0].data;
|
||||
} else if (viewOrContainer.child) {
|
||||
next = viewOrContainer.child;
|
||||
} else if (viewOrContainer.next) {
|
||||
cleanUpView(viewOrContainer as LView);
|
||||
next = viewOrContainer.next;
|
||||
}
|
||||
|
||||
if (next == null) {
|
||||
while (viewOrContainerState && !viewOrContainerState !.next) {
|
||||
cleanUpView(viewOrContainerState as ViewState);
|
||||
viewOrContainerState = getParentState(viewOrContainerState, rootView);
|
||||
while (viewOrContainer && !viewOrContainer !.next) {
|
||||
cleanUpView(viewOrContainer as LView);
|
||||
viewOrContainer = getParentState(viewOrContainer, rootView);
|
||||
}
|
||||
cleanUpView(viewOrContainerState as ViewState || rootView);
|
||||
cleanUpView(viewOrContainer as LView || rootView);
|
||||
|
||||
next = viewOrContainerState && viewOrContainerState.next;
|
||||
next = viewOrContainer && viewOrContainer.next;
|
||||
}
|
||||
viewOrContainerState = next;
|
||||
viewOrContainer = next;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,7 +189,8 @@ export function destroyViewTree(rootView: ViewState): void {
|
|||
* @param index The index at which to insert the view
|
||||
* @returns The inserted view
|
||||
*/
|
||||
export function insertView(container: LContainer, newView: LView, index: number): LView {
|
||||
export function insertView(
|
||||
container: LContainerNode, newView: LViewNode, index: number): LViewNode {
|
||||
const state = container.data;
|
||||
const views = state.views;
|
||||
|
||||
|
@ -232,7 +235,7 @@ export function insertView(container: LContainer, newView: LView, index: number)
|
|||
* @param removeIndex The index of the view to remove
|
||||
* @returns The removed view
|
||||
*/
|
||||
export function removeView(container: LContainer, removeIndex: number): LView {
|
||||
export function removeView(container: LContainerNode, removeIndex: number): LViewNode {
|
||||
const views = container.data.views;
|
||||
const viewNode = views[removeIndex];
|
||||
if (removeIndex > 0) {
|
||||
|
@ -248,34 +251,32 @@ export function removeView(container: LContainer, removeIndex: number): LView {
|
|||
|
||||
/**
|
||||
* Sets a next on the view node, so views in for loops can easily jump from
|
||||
* one view to the next to add/remove elements. Also adds the ViewState (view.data)
|
||||
* one view to the next to add/remove elements. Also adds the LView (view.data)
|
||||
* to the view tree for easy traversal when cleaning up the view.
|
||||
*
|
||||
* @param view The view to set up
|
||||
* @param next The view's new next
|
||||
*/
|
||||
export function setViewNext(view: LView, next: LView | null): void {
|
||||
export function setViewNext(view: LViewNode, next: LViewNode | null): void {
|
||||
view.next = next;
|
||||
view.data.next = next ? next.data : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines which ViewOrContainerState to jump to when traversing back up the
|
||||
* Determines which LViewOrLContainer to jump to when traversing back up the
|
||||
* tree in destroyViewTree.
|
||||
*
|
||||
* Normally, the view's parent ViewState should be checked, but in the case of
|
||||
* Normally, the view's parent LView should be checked, but in the case of
|
||||
* embedded views, the container (which is the view node's parent, but not the
|
||||
* ViewState's parent) needs to be checked for a possible next property.
|
||||
* LView's parent) needs to be checked for a possible next property.
|
||||
*
|
||||
* @param state The ViewOrContainerState for which we need a parent state
|
||||
* @param state The LViewOrLContainer for which we need a parent state
|
||||
* @param rootView The rootView, so we don't propagate too far up the view tree
|
||||
* @returns The correct parent ViewOrContainerState
|
||||
* @returns The correct parent LViewOrLContainer
|
||||
*/
|
||||
export function getParentState(
|
||||
state: ViewOrContainerState, rootView: ViewState): ViewOrContainerState|null {
|
||||
export function getParentState(state: LViewOrLContainer, rootView: LView): LViewOrLContainer|null {
|
||||
let node;
|
||||
if ((node = (state as ViewState) !.node) &&
|
||||
(node.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.View) {
|
||||
if ((node = (state as LView) !.node) && (node.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.View) {
|
||||
// if it's an embedded view, the state needs to go up to the container, in case the
|
||||
// container has a next
|
||||
return node.parent !.data as any;
|
||||
|
@ -288,11 +289,11 @@ export function getParentState(
|
|||
/**
|
||||
* Removes all listeners and call all onDestroys in a given view.
|
||||
*
|
||||
* @param viewState The ViewState of the view to clean up
|
||||
* @param view The LView to clean up
|
||||
*/
|
||||
function cleanUpView(viewState: ViewState): void {
|
||||
if (!viewState.cleanup) return;
|
||||
const cleanup = viewState.cleanup !;
|
||||
function cleanUpView(view: LView): void {
|
||||
if (!view.cleanup) return;
|
||||
const cleanup = view.cleanup !;
|
||||
for (let i = 0; i < cleanup.length - 1; i += 2) {
|
||||
if (typeof cleanup[i] === 'string') {
|
||||
cleanup ![i + 1].removeEventListener(cleanup[i], cleanup[i + 2], cleanup[i + 3]);
|
||||
|
@ -301,7 +302,7 @@ function cleanUpView(viewState: ViewState): void {
|
|||
cleanup[i].call(cleanup[i + 1]);
|
||||
}
|
||||
}
|
||||
viewState.cleanup = null;
|
||||
view.cleanup = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -314,10 +315,10 @@ function cleanUpView(viewState: ViewState): void {
|
|||
*
|
||||
* @param parent The parent to which to append the child
|
||||
* @param child The child that should be appended
|
||||
* @param currentView The current view's ViewState
|
||||
* @param currentView The current LView
|
||||
* @returns Whether or not the child was appended
|
||||
*/
|
||||
export function appendChild(parent: LNode, child: RNode | null, currentView: ViewState): boolean {
|
||||
export function appendChild(parent: LNode, child: RNode | null, currentView: LView): boolean {
|
||||
// Only add native child element to parent element if the parent element is regular Element.
|
||||
// If parent is:
|
||||
// - Regular element => add child
|
||||
|
@ -350,9 +351,9 @@ export function appendChild(parent: LNode, child: RNode | null, currentView: Vie
|
|||
* the content projection system. Otherwise, insertBefore normally.
|
||||
*
|
||||
* @param node Node to insert
|
||||
* @param currentView The current view's ViewState
|
||||
* @param currentView Current LView
|
||||
*/
|
||||
export function insertChild(node: LNode, currentView: ViewState): void {
|
||||
export function insertChild(node: LNode, currentView: LView): void {
|
||||
const parent = node.parent !;
|
||||
// Only add child element to parent element if the parent element is regular Element.
|
||||
// If parent is:
|
||||
|
@ -389,11 +390,11 @@ export function insertChild(node: LNode, currentView: ViewState): void {
|
|||
* @param projectedNodes Array to store the projected node
|
||||
* @param node The node to process
|
||||
* @param currentParent The last parent element to be processed
|
||||
* @param currentView The current view's ViewState
|
||||
* @param currentView Current LView
|
||||
*/
|
||||
export function processProjectedNode(
|
||||
projectedNodes: ProjectionState, node: LElement | LText | LContainer,
|
||||
currentParent: LView | LElement, currentView: ViewState): void {
|
||||
projectedNodes: LProjection, node: LElementNode | LTextNode | LContainerNode,
|
||||
currentParent: LViewNode | LElementNode, currentView: LView): void {
|
||||
if ((node.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.Container &&
|
||||
(currentParent.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.Element &&
|
||||
(currentParent.data === null || currentParent.data === currentView)) {
|
||||
|
@ -402,11 +403,11 @@ export function processProjectedNode(
|
|||
// Alternatively a container is projected at the root of a component's template
|
||||
// and can't be re-projected (as not content of any component).
|
||||
// Assignee the final projection location in those cases.
|
||||
const containerState = (node as LContainer).data;
|
||||
containerState.renderParent = currentParent as LElement;
|
||||
const views = containerState.views;
|
||||
const lContainer = (node as LContainerNode).data;
|
||||
lContainer.renderParent = currentParent as LElementNode;
|
||||
const views = lContainer.views;
|
||||
for (let i = 0; i < views.length; i++) {
|
||||
addRemoveViewFromContainer(node as LContainer, views[i], true, null);
|
||||
addRemoveViewFromContainer(node as LContainerNode, views[i], true, null);
|
||||
}
|
||||
}
|
||||
projectedNodes.push(node);
|
||||
|
|
|
@ -10,7 +10,7 @@ import './ng_dev_mode';
|
|||
|
||||
import {assertNotNull} from './assert';
|
||||
import {CssSelector, CssSelectorWithNegations, SimpleCssSelector} from './interfaces';
|
||||
import {LNodeStatic} from './l_node_static';
|
||||
import {TNode} from './t_node';
|
||||
|
||||
function isCssClassMatching(nodeClassAttrVal: string, cssClassToMatch: string): boolean {
|
||||
const nodeClassesLen = nodeClassAttrVal.length;
|
||||
|
@ -33,14 +33,13 @@ function isCssClassMatching(nodeClassAttrVal: string, cssClassToMatch: string):
|
|||
* @param selector
|
||||
* @returns true if node matches the selector.
|
||||
*/
|
||||
export function isNodeMatchingSimpleSelector(
|
||||
lNodeStaticData: LNodeStatic, selector: SimpleCssSelector): boolean {
|
||||
export function isNodeMatchingSimpleSelector(tNode: TNode, selector: SimpleCssSelector): boolean {
|
||||
const noOfSelectorParts = selector.length;
|
||||
ngDevMode && assertNotNull(selector[0], 'selector[0]');
|
||||
const tagNameInSelector = selector[0];
|
||||
|
||||
// check tag tame
|
||||
if (tagNameInSelector !== '' && tagNameInSelector !== lNodeStaticData.tagName) {
|
||||
if (tagNameInSelector !== '' && tagNameInSelector !== tNode.tagName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -50,11 +49,11 @@ export function isNodeMatchingSimpleSelector(
|
|||
}
|
||||
|
||||
// short-circuit case where an element has no attrs but a selector tries to match some
|
||||
if (noOfSelectorParts > 1 && !lNodeStaticData.attrs) {
|
||||
if (noOfSelectorParts > 1 && !tNode.attrs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const attrsInNode = lNodeStaticData.attrs !;
|
||||
const attrsInNode = tNode.attrs !;
|
||||
|
||||
for (let i = 1; i < noOfSelectorParts; i += 2) {
|
||||
const attrNameInSelector = selector[i];
|
||||
|
@ -84,10 +83,9 @@ export function isNodeMatchingSimpleSelector(
|
|||
}
|
||||
|
||||
export function isNodeMatchingSelectorWithNegations(
|
||||
lNodeStaticData: LNodeStatic, selector: CssSelectorWithNegations): boolean {
|
||||
tNode: TNode, selector: CssSelectorWithNegations): boolean {
|
||||
const positiveSelector = selector[0];
|
||||
if (positiveSelector != null &&
|
||||
!isNodeMatchingSimpleSelector(lNodeStaticData, positiveSelector)) {
|
||||
if (positiveSelector != null && !isNodeMatchingSimpleSelector(tNode, positiveSelector)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -96,7 +94,7 @@ export function isNodeMatchingSelectorWithNegations(
|
|||
if (negativeSelectors) {
|
||||
for (let i = 0; i < negativeSelectors.length; i++) {
|
||||
// if one of negative selectors matched than the whole selector doesn't match
|
||||
if (isNodeMatchingSimpleSelector(lNodeStaticData, negativeSelectors[i])) {
|
||||
if (isNodeMatchingSimpleSelector(tNode, negativeSelectors[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -105,10 +103,9 @@ export function isNodeMatchingSelectorWithNegations(
|
|||
return true;
|
||||
}
|
||||
|
||||
export function isNodeMatchingSelector(
|
||||
lNodeStaticData: LNodeStatic, selector: CssSelector): boolean {
|
||||
export function isNodeMatchingSelector(tNode: TNode, selector: CssSelector): boolean {
|
||||
for (let i = 0; i < selector.length; i++) {
|
||||
if (isNodeMatchingSelectorWithNegations(lNodeStaticData, selector[i])) {
|
||||
if (isNodeMatchingSelectorWithNegations(tNode, selector[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,11 @@ import {Type} from '../type';
|
|||
import {assertNotNull} from './assert';
|
||||
import {DirectiveDef} from './definition_interfaces';
|
||||
import {getOrCreateContainerRef, getOrCreateElementRef, getOrCreateNodeInjectorForNode, getOrCreateTemplateRef} from './di';
|
||||
import {LContainer, LElement, LNode, LNodeFlags, LNodeInjector, LView, QueryReadType, QueryState} from './interfaces';
|
||||
import {LNodeStatic} from './l_node_static';
|
||||
import {LContainerNode, LElementNode, LInjector, LNode, LNodeFlags, LQuery, LViewNode, QueryReadType} from './interfaces';
|
||||
import {assertNodeOfPossibleTypes} from './node_assert';
|
||||
import {TNode} from './t_node';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A predicate which determines if a given element/directive should be included in the query
|
||||
|
@ -37,7 +39,7 @@ export interface QueryPredicate<T> {
|
|||
list: QueryList<T>;
|
||||
|
||||
/**
|
||||
* If looking for directives than it contains the directive type.
|
||||
* If looking for directives then it contains the directive type.
|
||||
*/
|
||||
type: Type<T>|null;
|
||||
|
||||
|
@ -59,7 +61,7 @@ export interface QueryPredicate<T> {
|
|||
values: any[];
|
||||
}
|
||||
|
||||
export class QueryState_ implements QueryState {
|
||||
export class LQuery_ implements LQuery {
|
||||
shallow: QueryPredicate<any>|null = null;
|
||||
deep: QueryPredicate<any>|null = null;
|
||||
|
||||
|
@ -78,9 +80,9 @@ export class QueryState_ implements QueryState {
|
|||
}
|
||||
}
|
||||
|
||||
child(): QueryState|null {
|
||||
child(): LQuery|null {
|
||||
if (this.deep === null) {
|
||||
// if we don't have any deep queries than no need to track anything more.
|
||||
// if we don't have any deep queries then no need to track anything more.
|
||||
return null;
|
||||
}
|
||||
if (this.shallow === null) {
|
||||
|
@ -89,7 +91,7 @@ export class QueryState_ implements QueryState {
|
|||
return this;
|
||||
} else {
|
||||
// We need to create new state
|
||||
return new QueryState_(this.deep);
|
||||
return new LQuery_(this.deep);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,11 +100,11 @@ export class QueryState_ implements QueryState {
|
|||
add(this.deep, node);
|
||||
}
|
||||
|
||||
insertView(container: LContainer, view: LView, index: number): void {
|
||||
insertView(container: LContainerNode, view: LViewNode, index: number): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
removeView(container: LContainer, view: LView, index: number): void {
|
||||
removeView(container: LContainerNode, view: LViewNode, index: number): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
|
@ -111,12 +113,12 @@ export class QueryState_ implements QueryState {
|
|||
* Iterates over local names for a given node and returns directive index
|
||||
* (or -1 if a local name points to an element).
|
||||
*
|
||||
* @param staticData static data of a node to check
|
||||
* @param tNode static data of a node to check
|
||||
* @param selector selector to match
|
||||
* @returns directive index, -1 or null if a selector didn't match any of the local names
|
||||
*/
|
||||
function getIdxOfMatchingSelector(staticData: LNodeStatic, selector: string): number|null {
|
||||
const localNames = staticData.localNames;
|
||||
function getIdxOfMatchingSelector(tNode: TNode, selector: string): number|null {
|
||||
const localNames = tNode.localNames;
|
||||
if (localNames) {
|
||||
for (let i = 0; i < localNames.length; i += 2) {
|
||||
if (localNames[i] === selector) {
|
||||
|
@ -148,7 +150,7 @@ function geIdxOfMatchingDirective(node: LNode, type: Type<any>): number|null {
|
|||
return null;
|
||||
}
|
||||
|
||||
function readDefaultInjectable(nodeInjector: LNodeInjector, node: LNode): viewEngine_ElementRef|
|
||||
function readDefaultInjectable(nodeInjector: LInjector, node: LNode): viewEngine_ElementRef|
|
||||
viewEngine_TemplateRef<any>|undefined {
|
||||
ngDevMode && assertNodeOfPossibleTypes(node, LNodeFlags.Container, LNodeFlags.Element);
|
||||
if ((node.flags & LNodeFlags.TYPE_MASK) === LNodeFlags.Element) {
|
||||
|
@ -159,7 +161,7 @@ function readDefaultInjectable(nodeInjector: LNodeInjector, node: LNode): viewEn
|
|||
}
|
||||
|
||||
function readFromNodeInjector(
|
||||
nodeInjector: LNodeInjector, node: LNode, read: QueryReadType | Type<any>): any {
|
||||
nodeInjector: LInjector, node: LNode, read: QueryReadType | Type<any>): any {
|
||||
if (read === QueryReadType.ElementRef) {
|
||||
return getOrCreateElementRef(nodeInjector);
|
||||
} else if (read === QueryReadType.ViewContainerRef) {
|
||||
|
@ -176,7 +178,7 @@ function readFromNodeInjector(
|
|||
}
|
||||
|
||||
function add(predicate: QueryPredicate<any>| null, node: LNode) {
|
||||
const nodeInjector = getOrCreateNodeInjectorForNode(node as LElement | LContainer);
|
||||
const nodeInjector = getOrCreateNodeInjectorForNode(node as LElementNode | LContainerNode);
|
||||
while (predicate) {
|
||||
const type = predicate.type;
|
||||
if (type) {
|
||||
|
@ -194,8 +196,8 @@ function add(predicate: QueryPredicate<any>| null, node: LNode) {
|
|||
} else {
|
||||
const selector = predicate.selector !;
|
||||
for (let i = 0; i < selector.length; i++) {
|
||||
ngDevMode && assertNotNull(node.staticData, 'node.staticData');
|
||||
const directiveIdx = getIdxOfMatchingSelector(node.staticData !, selector[i]);
|
||||
ngDevMode && assertNotNull(node.tNode, 'node.tNode');
|
||||
const directiveIdx = getIdxOfMatchingSelector(node.tNode !, selector[i]);
|
||||
// is anything on a node matching a selector?
|
||||
if (directiveIdx !== null) {
|
||||
if (predicate.read !== null) {
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import {DirectiveDef} from './definition_interfaces';
|
||||
|
||||
/** The type of the global ngStaticData array. */
|
||||
export type NgStaticData = (LNodeStatic | DirectiveDef<any>| null)[];
|
||||
export type NgStaticData = (TNode | DirectiveDef<any>| null)[];
|
||||
|
||||
/**
|
||||
* LNode binding data (flyweight) for a particular node that is shared between all templates
|
||||
|
@ -22,7 +22,7 @@ export type NgStaticData = (LNodeStatic | DirectiveDef<any>| null)[];
|
|||
*
|
||||
* see: https://en.wikipedia.org/wiki/Flyweight_pattern for more on the Flyweight pattern
|
||||
*/
|
||||
export interface LNodeStatic {
|
||||
export interface TNode {
|
||||
/** The tag name associated with this node. */
|
||||
tagName: string|null;
|
||||
|
||||
|
@ -72,7 +72,7 @@ export interface LNodeStatic {
|
|||
outputs: PropertyAliases|null|undefined;
|
||||
|
||||
/**
|
||||
* If this LNodeStatic corresponds to an LContainer, the container will
|
||||
* If this TNode corresponds to an LContainerNode, the container will
|
||||
* need to have nested static data for each of its embedded views.
|
||||
* Otherwise, nodes in embedded views with the same index as nodes
|
||||
* in their parent views will overwrite each other, as they are in
|
||||
|
@ -86,14 +86,14 @@ export interface LNodeStatic {
|
|||
* [{tagName: 'button', attrs ...}, null] // V(1) ngData
|
||||
* ]
|
||||
*/
|
||||
containerStatic: (LNodeStatic|null)[][]|null;
|
||||
containerStatic: (TNode|null)[][]|null;
|
||||
}
|
||||
|
||||
/** Static data for an LElement */
|
||||
export interface LElementStatic extends LNodeStatic { containerStatic: null; }
|
||||
/** Static data for an LElementNode */
|
||||
export interface TElementNode extends TNode { containerStatic: null; }
|
||||
|
||||
/** Static data for an LContainer */
|
||||
export interface LContainerStatic extends LNodeStatic { containerStatic: (LNodeStatic|null)[][]; }
|
||||
/** Static data for an LContainerNode */
|
||||
export interface TContainerNode extends TNode { containerStatic: (TNode|null)[][]; }
|
||||
|
||||
/**
|
||||
* This mapping is necessary so we can set input properties and output listeners
|
|
@ -10,8 +10,8 @@ import {ElementRef, TemplateRef, ViewContainerRef} from '@angular/core';
|
|||
|
||||
import {bloomAdd, bloomFindPossibleInjector} from '../../src/render3/di';
|
||||
import {C, D, E, PublicFeature, T, V, b, b2, c, cR, cr, defineDirective, e, inject, injectElementRef, injectTemplateRef, injectViewContainerRef, t, v} from '../../src/render3/index';
|
||||
import {createLNode, createViewState, enterView, getOrCreateNodeInjector, leaveView} from '../../src/render3/instructions';
|
||||
import {LNodeFlags, LNodeInjector} from '../../src/render3/interfaces';
|
||||
import {createLNode, createLView, enterView, getOrCreateNodeInjector, leaveView} from '../../src/render3/instructions';
|
||||
import {LInjector, LNodeFlags} from '../../src/render3/interfaces';
|
||||
|
||||
import {renderToHtml} from './render_util';
|
||||
|
||||
|
@ -213,7 +213,7 @@ describe('di', () => {
|
|||
|
||||
describe('inject', () => {
|
||||
describe('bloom filter', () => {
|
||||
let di: LNodeInjector;
|
||||
let di: LInjector;
|
||||
beforeEach(() => {
|
||||
di = {} as any;
|
||||
di.bf0 = 0;
|
||||
|
@ -318,7 +318,7 @@ describe('di', () => {
|
|||
|
||||
describe('getOrCreateNodeInjector', () => {
|
||||
it('should handle initial undefined state', () => {
|
||||
const contentView = createViewState(-1, null !, []);
|
||||
const contentView = createLView(-1, null !, []);
|
||||
const oldView = enterView(contentView, null !);
|
||||
try {
|
||||
const parent = createLNode(0, LNodeFlags.Element, null, null);
|
||||
|
|
|
@ -7,10 +7,10 @@
|
|||
*/
|
||||
|
||||
import {CssSelector, CssSelectorWithNegations, SimpleCssSelector} from '../../src/render3/interfaces';
|
||||
import {LNodeStatic} from '../../src/render3/l_node_static';
|
||||
import {isNodeMatchingSelector, isNodeMatchingSelectorWithNegations, isNodeMatchingSimpleSelector} from '../../src/render3/node_selector_matcher';
|
||||
import {TNode} from '../../src/render3/t_node';
|
||||
|
||||
function testLStaticData(tagName: string, attrs: string[] | null): LNodeStatic {
|
||||
function testLStaticData(tagName: string, attrs: string[] | null): TNode {
|
||||
return {
|
||||
tagName,
|
||||
attrs,
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
|
||||
import {stringifyElement} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {ComponentTemplate, ComponentType, DirectiveType, PublicFeature, defineComponent, defineDirective, renderComponent as _renderComponent} from '../../src/render3/index';
|
||||
import {NG_HOST_SYMBOL, createLNode, createViewState, renderTemplate} from '../../src/render3/instructions';
|
||||
import {LElement, LNodeFlags} from '../../src/render3/interfaces';
|
||||
import {NG_HOST_SYMBOL, createLNode, createLView, renderTemplate} from '../../src/render3/instructions';
|
||||
import {LElementNode, LNodeFlags} from '../../src/render3/interfaces';
|
||||
import {RElement, RText, Renderer3, RendererFactory3, domRendererFactory3} from '../../src/render3/renderer';
|
||||
import {getRendererFactory2} from './imported_renderer2';
|
||||
|
||||
export const document = ((global || window) as any).document;
|
||||
export let containerEl: HTMLElement = null !;
|
||||
let host: LElement|null;
|
||||
let host: LElementNode|null;
|
||||
const isRenderer2 =
|
||||
typeof process == 'object' && process.argv[3] && process.argv[3] === '--r=renderer2';
|
||||
// tslint:disable-next-line:no-console
|
||||
|
@ -63,7 +63,7 @@ export function renderComponent<T>(type: ComponentType<T>, rendererFactory?: Ren
|
|||
}
|
||||
|
||||
export function toHtml<T>(componentOrElement: T | RElement): string {
|
||||
const node = (componentOrElement as any)[NG_HOST_SYMBOL] as LElement;
|
||||
const node = (componentOrElement as any)[NG_HOST_SYMBOL] as LElementNode;
|
||||
if (node) {
|
||||
return toHtml(node.native);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue