feat(core): view engine - support content projection (#14209)
Part of #14013 PR Close #14209
This commit is contained in:
parent
86b2b2504f
commit
0a29574d98
|
@ -13,8 +13,8 @@ import {BindingDef, BindingType, DebugContext, DisposableFn, ElementData, Elemen
|
|||
import {checkAndUpdateBinding, entryAction, setBindingDebugInfo, setCurrentNode, sliceErrorStack} from './util';
|
||||
|
||||
export function anchorDef(
|
||||
flags: NodeFlags, matchedQueries: [string, QueryValueType][], childCount: number,
|
||||
template?: ViewDefinition): NodeDef {
|
||||
flags: NodeFlags, matchedQueries: [string, QueryValueType][], ngContentIndex: number,
|
||||
childCount: number, template?: ViewDefinition): NodeDef {
|
||||
const matchedQueryDefs: {[queryId: string]: QueryValueType} = {};
|
||||
if (matchedQueries) {
|
||||
matchedQueries.forEach(([queryId, valueType]) => { matchedQueryDefs[queryId] = valueType; });
|
||||
|
@ -33,7 +33,7 @@ export function anchorDef(
|
|||
disposableIndex: undefined,
|
||||
// regular values
|
||||
flags,
|
||||
matchedQueries: matchedQueryDefs, childCount,
|
||||
matchedQueries: matchedQueryDefs, ngContentIndex, childCount,
|
||||
bindings: [],
|
||||
disposableCount: 0,
|
||||
element: {
|
||||
|
@ -41,18 +41,19 @@ export function anchorDef(
|
|||
attrs: undefined,
|
||||
outputs: [], template,
|
||||
// will bet set by the view definition
|
||||
providerIndices: undefined, source
|
||||
providerIndices: undefined, source,
|
||||
},
|
||||
provider: undefined,
|
||||
text: undefined,
|
||||
pureExpression: undefined,
|
||||
query: undefined,
|
||||
ngContent: undefined
|
||||
};
|
||||
}
|
||||
|
||||
export function elementDef(
|
||||
flags: NodeFlags, matchedQueries: [string, QueryValueType][], childCount: number, name: string,
|
||||
fixedAttrs: {[name: string]: string} = {},
|
||||
flags: NodeFlags, matchedQueries: [string, QueryValueType][], ngContentIndex: number,
|
||||
childCount: number, name: string, fixedAttrs: {[name: string]: string} = {},
|
||||
bindings?:
|
||||
([BindingType.ElementClass, string] | [BindingType.ElementStyle, string, string] |
|
||||
[BindingType.ElementAttribute | BindingType.ElementProperty, string, SecurityContext])[],
|
||||
|
@ -108,7 +109,7 @@ export function elementDef(
|
|||
disposableIndex: undefined,
|
||||
// regular values
|
||||
flags,
|
||||
matchedQueries: matchedQueryDefs, childCount,
|
||||
matchedQueries: matchedQueryDefs, ngContentIndex, childCount,
|
||||
bindings: bindingDefs,
|
||||
disposableCount: outputDefs.length,
|
||||
element: {
|
||||
|
@ -117,12 +118,13 @@ export function elementDef(
|
|||
outputs: outputDefs,
|
||||
template: undefined,
|
||||
// will bet set by the view definition
|
||||
providerIndices: undefined, source
|
||||
providerIndices: undefined, source,
|
||||
},
|
||||
provider: undefined,
|
||||
text: undefined,
|
||||
pureExpression: undefined,
|
||||
query: undefined,
|
||||
ngContent: undefined
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
*/
|
||||
|
||||
export {anchorDef, elementDef} from './element';
|
||||
export {ngContentDef} from './ng_content';
|
||||
export {providerDef} from './provider';
|
||||
export {pureArrayDef, pureObjectDef, purePipeDef} from './pure_expression';
|
||||
export {queryDef} from './query';
|
||||
export {textDef} from './text';
|
||||
export {setCurrentNode} from './util';
|
||||
export {rootRenderNodes, setCurrentNode} from './util';
|
||||
export {checkAndUpdateView, checkNoChangesView, checkNodeDynamic, checkNodeInline, createEmbeddedView, createRootView, destroyView, viewDef} from './view';
|
||||
export {attachEmbeddedView, detachEmbeddedView, rootRenderNodes} from './view_attach';
|
||||
export {attachEmbeddedView, detachEmbeddedView} from './view_attach';
|
||||
|
||||
export * from './types';
|
||||
export {DefaultServices} from './services';
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NodeDef, NodeType, ViewData, asElementData} from './types';
|
||||
import {RenderNodeAction, visitProjectedRenderNodes} from './util';
|
||||
|
||||
export function ngContentDef(ngContentIndex: number, index: number): NodeDef {
|
||||
return {
|
||||
type: NodeType.NgContent,
|
||||
// will bet set by the view definition
|
||||
index: undefined,
|
||||
reverseChildIndex: undefined,
|
||||
parent: undefined,
|
||||
childFlags: undefined,
|
||||
childMatchedQueries: undefined,
|
||||
bindingIndex: undefined,
|
||||
disposableIndex: undefined,
|
||||
// regular values
|
||||
flags: 0,
|
||||
matchedQueries: {}, ngContentIndex,
|
||||
childCount: 0,
|
||||
bindings: [],
|
||||
disposableCount: 0,
|
||||
element: undefined,
|
||||
provider: undefined,
|
||||
text: undefined,
|
||||
pureExpression: undefined,
|
||||
query: undefined,
|
||||
ngContent: {index}
|
||||
};
|
||||
}
|
||||
|
||||
export function appendNgContent(view: ViewData, renderHost: any, def: NodeDef) {
|
||||
if (def.ngContentIndex != null) {
|
||||
// Do nothing if we are reprojected!
|
||||
return;
|
||||
}
|
||||
const parentEl = def.parent != null ? asElementData(view, def.parent).renderElement : renderHost;
|
||||
if (!parentEl) {
|
||||
// Nothing to do if there is no parent element.
|
||||
return;
|
||||
}
|
||||
const ngContentIndex = def.ngContent.index;
|
||||
if (view.renderer) {
|
||||
const projectedNodes: any[] = [];
|
||||
visitProjectedRenderNodes(
|
||||
view, ngContentIndex, RenderNodeAction.Collect, undefined, undefined, projectedNodes);
|
||||
view.renderer.projectNodes(parentEl, projectedNodes);
|
||||
} else {
|
||||
visitProjectedRenderNodes(
|
||||
view, ngContentIndex, RenderNodeAction.AppendChild, parentEl, undefined, undefined);
|
||||
}
|
||||
}
|
|
@ -80,7 +80,8 @@ export function providerDef(
|
|||
disposableIndex: undefined,
|
||||
// regular values
|
||||
flags,
|
||||
matchedQueries: matchedQueryDefs, childCount, bindings,
|
||||
matchedQueries: matchedQueryDefs,
|
||||
ngContentIndex: undefined, childCount, bindings,
|
||||
disposableCount: outputDefs.length,
|
||||
element: undefined,
|
||||
provider: {
|
||||
|
@ -91,7 +92,8 @@ export function providerDef(
|
|||
},
|
||||
text: undefined,
|
||||
pureExpression: undefined,
|
||||
query: undefined
|
||||
query: undefined,
|
||||
ngContent: undefined
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ function _pureExpressionDef(
|
|||
// regular values
|
||||
flags: 0,
|
||||
matchedQueries: {},
|
||||
ngContentIndex: undefined,
|
||||
childCount: 0, bindings,
|
||||
disposableCount: 0,
|
||||
element: undefined,
|
||||
|
@ -57,6 +58,7 @@ function _pureExpressionDef(
|
|||
text: undefined,
|
||||
pureExpression: {type, pipeDep},
|
||||
query: undefined,
|
||||
ngContent: undefined
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ export function queryDef(
|
|||
disposableIndex: undefined,
|
||||
// regular values
|
||||
flags,
|
||||
ngContentIndex: undefined,
|
||||
matchedQueries: {},
|
||||
childCount: 0,
|
||||
bindings: [],
|
||||
|
@ -42,7 +43,8 @@ export function queryDef(
|
|||
provider: undefined,
|
||||
text: undefined,
|
||||
pureExpression: undefined,
|
||||
query: {id, bindings: bindingDefs}
|
||||
query: {id, bindings: bindingDefs},
|
||||
ngContent: undefined
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -19,9 +19,9 @@ import {Sanitizer, SecurityContext} from '../security';
|
|||
import {createInjector} from './provider';
|
||||
import {getQueryValue} from './query';
|
||||
import {DebugContext, ElementData, NodeData, NodeDef, NodeType, Services, ViewData, ViewDefinition, asElementData} from './types';
|
||||
import {isComponentView, renderNode} from './util';
|
||||
import {isComponentView, renderNode, rootRenderNodes} from './util';
|
||||
import {checkAndUpdateView, checkNoChangesView, createEmbeddedView, destroyView} from './view';
|
||||
import {attachEmbeddedView, detachEmbeddedView, rootRenderNodes} from './view_attach';
|
||||
import {attachEmbeddedView, detachEmbeddedView} from './view_attach';
|
||||
|
||||
@Injectable()
|
||||
export class DefaultServices implements Services {
|
||||
|
@ -140,6 +140,10 @@ class DebugContext_ implements DebugContext {
|
|||
private nodeDef: NodeDef;
|
||||
private elDef: NodeDef;
|
||||
constructor(public view: ViewData, public nodeIndex: number) {
|
||||
if (nodeIndex == null) {
|
||||
this.nodeIndex = nodeIndex = view.parentIndex;
|
||||
this.view = view = view.parent;
|
||||
}
|
||||
this.nodeDef = view.def.nodes[nodeIndex];
|
||||
this.elDef = findElementDef(view, nodeIndex);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import {looseIdentical} from '../facade/lang';
|
|||
import {BindingDef, BindingType, DebugContext, NodeData, NodeDef, NodeFlags, NodeType, Services, TextData, ViewData, ViewFlags, asElementData, asTextData} from './types';
|
||||
import {checkAndUpdateBinding, sliceErrorStack} from './util';
|
||||
|
||||
export function textDef(constants: string[]): NodeDef {
|
||||
export function textDef(ngContentIndex: number, constants: string[]): NodeDef {
|
||||
// skip the call to sliceErrorStack itself + the call to this function.
|
||||
const source = isDevMode() ? sliceErrorStack(2, 3) : '';
|
||||
const bindings: BindingDef[] = new Array(constants.length - 1);
|
||||
|
@ -37,7 +37,7 @@ export function textDef(constants: string[]): NodeDef {
|
|||
disposableIndex: undefined,
|
||||
// regular values
|
||||
flags: 0,
|
||||
matchedQueries: {},
|
||||
matchedQueries: {}, ngContentIndex,
|
||||
childCount: 0, bindings,
|
||||
disposableCount: 0,
|
||||
element: undefined,
|
||||
|
@ -45,6 +45,7 @@ export function textDef(constants: string[]): NodeDef {
|
|||
text: {prefix: constants[0], source},
|
||||
pureExpression: undefined,
|
||||
query: undefined,
|
||||
ngContent: undefined
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -24,14 +24,14 @@ export interface ViewDefinition {
|
|||
handleEvent: ViewHandleEventFn;
|
||||
/**
|
||||
* Order: Depth first.
|
||||
* Especially providers are before elements / anchros.
|
||||
* Especially providers are before elements / anchors.
|
||||
*/
|
||||
nodes: NodeDef[];
|
||||
/** aggregated NodeFlags for all nodes **/
|
||||
nodeFlags: NodeFlags;
|
||||
/**
|
||||
* Order: parents before children, but children in reverse order.
|
||||
* Especially providers are after elements / anchros.
|
||||
* Especially providers are after elements / anchors.
|
||||
*/
|
||||
reverseChildNodes: NodeDef[];
|
||||
lastRootNode: NodeDef;
|
||||
|
@ -71,6 +71,8 @@ export interface NodeDef {
|
|||
reverseChildIndex: number;
|
||||
flags: NodeFlags;
|
||||
parent: number;
|
||||
/** this is checked against NgContentDef.index to find matched nodes */
|
||||
ngContentIndex: number;
|
||||
/** number of transitive children */
|
||||
childCount: number;
|
||||
/** aggregated NodeFlags for all children **/
|
||||
|
@ -94,6 +96,7 @@ export interface NodeDef {
|
|||
text: TextDef;
|
||||
pureExpression: PureExpressionDef;
|
||||
query: QueryDef;
|
||||
ngContent: NgContentDef;
|
||||
}
|
||||
|
||||
export enum NodeType {
|
||||
|
@ -102,6 +105,7 @@ export enum NodeType {
|
|||
Provider,
|
||||
PureExpression,
|
||||
Query,
|
||||
NgContent
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -229,6 +233,16 @@ export enum QueryBindingType {
|
|||
All
|
||||
}
|
||||
|
||||
export interface NgContentDef {
|
||||
/**
|
||||
* this index is checked against NodeDef.ngContentIndex to find the nodes
|
||||
* that are matched by this ng-content.
|
||||
* Note that a NodeDef with an ng-content can be reprojected, i.e.
|
||||
* have a ngContentIndex on its own.
|
||||
*/
|
||||
index: number;
|
||||
}
|
||||
|
||||
// -------------------------------------
|
||||
// Data
|
||||
// -------------------------------------
|
||||
|
|
|
@ -170,3 +170,82 @@ function callWithTryCatch(fn: (a: any) => any, arg: any): any {
|
|||
throw viewWrappedError(e, debugContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function rootRenderNodes(view: ViewData): any[] {
|
||||
const renderNodes: any[] = [];
|
||||
visitRootRenderNodes(view, RenderNodeAction.Collect, undefined, undefined, renderNodes);
|
||||
return renderNodes;
|
||||
}
|
||||
|
||||
export enum RenderNodeAction {
|
||||
Collect,
|
||||
AppendChild,
|
||||
InsertBefore,
|
||||
RemoveChild
|
||||
}
|
||||
|
||||
export function visitRootRenderNodes(
|
||||
view: ViewData, action: RenderNodeAction, parentNode: any, nextSibling: any, target: any[]) {
|
||||
const len = view.def.nodes.length;
|
||||
for (let i = 0; i < len; i++) {
|
||||
const nodeDef = view.def.nodes[i];
|
||||
visitRenderNode(view, nodeDef, action, parentNode, nextSibling, target);
|
||||
// jump to next sibling
|
||||
i += nodeDef.childCount;
|
||||
}
|
||||
}
|
||||
|
||||
export function visitProjectedRenderNodes(
|
||||
view: ViewData, ngContentIndex: number, action: RenderNodeAction, parentNode: any,
|
||||
nextSibling: any, target: any[]) {
|
||||
let compView = view;
|
||||
while (!isComponentView(compView)) {
|
||||
compView = compView.parent;
|
||||
}
|
||||
const hostView = compView.parent;
|
||||
const hostElDef = hostView.def.nodes[compView.parentIndex];
|
||||
const startIndex = hostElDef.index + 1;
|
||||
const endIndex = hostElDef.index + hostElDef.childCount;
|
||||
for (let i = startIndex; i <= endIndex; i++) {
|
||||
const nodeDef = hostView.def.nodes[i];
|
||||
if (nodeDef.ngContentIndex === ngContentIndex) {
|
||||
visitRenderNode(hostView, nodeDef, action, parentNode, nextSibling, target);
|
||||
}
|
||||
// jump to next sibling
|
||||
i += nodeDef.childCount;
|
||||
}
|
||||
}
|
||||
|
||||
function visitRenderNode(
|
||||
view: ViewData, nodeDef: NodeDef, action: RenderNodeAction, parentNode: any, nextSibling: any,
|
||||
target: any[]) {
|
||||
if (nodeDef.type === NodeType.NgContent) {
|
||||
visitProjectedRenderNodes(
|
||||
view, nodeDef.ngContent.index, action, parentNode, nextSibling, target);
|
||||
} else {
|
||||
const rn = renderNode(view, nodeDef);
|
||||
switch (action) {
|
||||
case RenderNodeAction.AppendChild:
|
||||
parentNode.appendChild(rn);
|
||||
break;
|
||||
case RenderNodeAction.InsertBefore:
|
||||
parentNode.insertBefore(rn, nextSibling);
|
||||
break;
|
||||
case RenderNodeAction.RemoveChild:
|
||||
parentNode.removeChild(rn);
|
||||
break;
|
||||
case RenderNodeAction.Collect:
|
||||
target.push(rn);
|
||||
break;
|
||||
}
|
||||
if (nodeDef.flags & NodeFlags.HasEmbeddedViews) {
|
||||
const embeddedViews = asElementData(view, nodeDef.index).embeddedViews;
|
||||
if (embeddedViews) {
|
||||
for (let k = 0; k < embeddedViews.length; k++) {
|
||||
visitRootRenderNodes(embeddedViews[k], action, parentNode, nextSibling, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import {RenderComponentType, Renderer} from '../render/api';
|
|||
|
||||
import {checkAndUpdateElementDynamic, checkAndUpdateElementInline, createElement} from './element';
|
||||
import {expressionChangedAfterItHasBeenCheckedError} from './errors';
|
||||
import {appendNgContent} from './ng_content';
|
||||
import {callLifecycleHooksChildrenFirst, checkAndUpdateProviderDynamic, checkAndUpdateProviderInline, createProvider} from './provider';
|
||||
import {checkAndUpdatePureExpressionDynamic, checkAndUpdatePureExpressionInline, createPureExpression} from './pure_expression';
|
||||
import {checkAndUpdateQuery, createQuery, queryDef} from './query';
|
||||
|
@ -316,6 +317,11 @@ function _createViewNodes(view: ViewData) {
|
|||
case NodeType.Query:
|
||||
nodeData = createQuery();
|
||||
break;
|
||||
case NodeType.NgContent:
|
||||
appendNgContent(view, renderHost, nodeDef);
|
||||
// no runtime data needed for NgContent...
|
||||
nodeData = undefined;
|
||||
break;
|
||||
}
|
||||
nodes[i] = nodeData;
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
|
||||
import {dirtyParentQuery} from './query';
|
||||
import {ElementData, NodeData, NodeFlags, NodeType, ViewData, asElementData, asProviderData, asTextData} from './types';
|
||||
import {declaredViewContainer, renderNode} from './util';
|
||||
import {ElementData, NodeData, NodeDef, NodeFlags, NodeType, ViewData, asElementData, asProviderData, asTextData} from './types';
|
||||
import {RenderNodeAction, declaredViewContainer, isComponentView, renderNode, rootRenderNodes, visitProjectedRenderNodes, visitRootRenderNodes} from './util';
|
||||
|
||||
export function attachEmbeddedView(elementData: ElementData, viewIndex: number, view: ViewData) {
|
||||
let embeddedViews = elementData.embeddedViews;
|
||||
|
@ -39,8 +39,8 @@ export function attachEmbeddedView(elementData: ElementData, viewIndex: number,
|
|||
const parentNode = prevRenderNode.parentNode;
|
||||
const nextSibling = prevRenderNode.nextSibling;
|
||||
if (parentNode) {
|
||||
const action = nextSibling ? DirectDomAction.InsertBefore : DirectDomAction.AppendChild;
|
||||
directDomAttachDetachSiblingRenderNodes(view, 0, action, parentNode, nextSibling);
|
||||
const action = nextSibling ? RenderNodeAction.InsertBefore : RenderNodeAction.AppendChild;
|
||||
visitRootRenderNodes(view, action, parentNode, nextSibling, undefined);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,8 +69,7 @@ export function detachEmbeddedView(elementData: ElementData, viewIndex: number):
|
|||
} else {
|
||||
const parentNode = elementData.renderElement.parentNode;
|
||||
if (parentNode) {
|
||||
directDomAttachDetachSiblingRenderNodes(
|
||||
view, 0, DirectDomAction.RemoveChild, parentNode, null);
|
||||
visitRootRenderNodes(view, RenderNodeAction.RemoveChild, parentNode, null, undefined);
|
||||
}
|
||||
}
|
||||
return view;
|
||||
|
@ -93,65 +92,3 @@ function removeFromArray(arr: any[], index: number) {
|
|||
arr.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
export function rootRenderNodes(view: ViewData): any[] {
|
||||
const renderNodes: any[] = [];
|
||||
collectSiblingRenderNodes(view, 0, renderNodes);
|
||||
return renderNodes;
|
||||
}
|
||||
|
||||
function collectSiblingRenderNodes(view: ViewData, startIndex: number, target: any[]) {
|
||||
const nodeCount = view.def.nodes.length;
|
||||
for (let i = startIndex; i < nodeCount; i++) {
|
||||
const nodeDef = view.def.nodes[i];
|
||||
target.push(renderNode(view, nodeDef));
|
||||
if (nodeDef.flags & NodeFlags.HasEmbeddedViews) {
|
||||
const embeddedViews = asElementData(view, i).embeddedViews;
|
||||
if (embeddedViews) {
|
||||
for (let k = 0; k < embeddedViews.length; k++) {
|
||||
collectSiblingRenderNodes(embeddedViews[k], 0, target);
|
||||
}
|
||||
}
|
||||
}
|
||||
// jump to next sibling
|
||||
i += nodeDef.childCount;
|
||||
}
|
||||
}
|
||||
|
||||
enum DirectDomAction {
|
||||
AppendChild,
|
||||
InsertBefore,
|
||||
RemoveChild
|
||||
}
|
||||
|
||||
function directDomAttachDetachSiblingRenderNodes(
|
||||
view: ViewData, startIndex: number, action: DirectDomAction, parentNode: any,
|
||||
nextSibling: any) {
|
||||
const nodeCount = view.def.nodes.length;
|
||||
for (let i = startIndex; i < nodeCount; i++) {
|
||||
const nodeDef = view.def.nodes[i];
|
||||
const rn = renderNode(view, nodeDef);
|
||||
switch (action) {
|
||||
case DirectDomAction.AppendChild:
|
||||
parentNode.appendChild(rn);
|
||||
break;
|
||||
case DirectDomAction.InsertBefore:
|
||||
parentNode.insertBefore(rn, nextSibling);
|
||||
break;
|
||||
case DirectDomAction.RemoveChild:
|
||||
parentNode.removeChild(rn);
|
||||
break;
|
||||
}
|
||||
if (nodeDef.flags & NodeFlags.HasEmbeddedViews) {
|
||||
const embeddedViews = asElementData(view, i).embeddedViews;
|
||||
if (embeddedViews) {
|
||||
for (let k = 0; k < embeddedViews.length; k++) {
|
||||
directDomAttachDetachSiblingRenderNodes(
|
||||
embeddedViews[k], 0, action, parentNode, nextSibling);
|
||||
}
|
||||
}
|
||||
}
|
||||
// jump to next sibling
|
||||
i += nodeDef.childCount;
|
||||
}
|
||||
}
|
|
@ -48,22 +48,24 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
describe('create', () => {
|
||||
it('should create anchor nodes without parents', () => {
|
||||
const rootNodes =
|
||||
createAndGetRootNodes(compViewDef([anchorDef(NodeFlags.None, null, 0)])).rootNodes;
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
anchorDef(NodeFlags.None, null, null, 0)
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should create views with multiple root anchor nodes', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
anchorDef(NodeFlags.None, null, 0), anchorDef(NodeFlags.None, null, 0)
|
||||
const rootNodes =
|
||||
createAndGetRootNodes(compViewDef([
|
||||
anchorDef(NodeFlags.None, null, null, 0), anchorDef(NodeFlags.None, null, null, 0)
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should create anchor nodes with parents', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
anchorDef(NodeFlags.None, null, 0),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
anchorDef(NodeFlags.None, null, null, 0),
|
||||
])).rootNodes;
|
||||
expect(getDOM().childNodes(rootNodes[0]).length).toBe(1);
|
||||
});
|
||||
|
@ -71,8 +73,8 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
if (!config.directDom) {
|
||||
it('should add debug information to the renderer', () => {
|
||||
const someContext = new Object();
|
||||
const {view, rootNodes} =
|
||||
createAndGetRootNodes(compViewDef([anchorDef(NodeFlags.None, null, 0)]), someContext);
|
||||
const {view, rootNodes} = createAndGetRootNodes(
|
||||
compViewDef([anchorDef(NodeFlags.None, null, null, 0)]), someContext);
|
||||
expect(getDebugNode(rootNodes[0]).nativeNode).toBe(asElementData(view, 0).renderElement);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -52,11 +52,11 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
}
|
||||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, AComp, [], null, null,
|
||||
() => compViewDef([
|
||||
elementDef(NodeFlags.None, null, 0, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span'),
|
||||
])),
|
||||
]));
|
||||
|
||||
|
@ -82,10 +82,10 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
const {view, rootNodes} = createAndGetRootNodes(
|
||||
compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
providerDef(NodeFlags.None, null, 0, AComp, [], null, null, () => compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 0, 'span', null, [[BindingType.ElementAttribute, 'a', SecurityContext.NONE]]),
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span', null, [[BindingType.ElementAttribute, 'a', SecurityContext.NONE]]),
|
||||
], update
|
||||
)),
|
||||
], jasmine.createSpy('parentUpdater')));
|
||||
|
@ -116,11 +116,11 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
}
|
||||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, AComp, [], null, null,
|
||||
() => compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.OnDestroy, null, 0, ChildProvider, [])
|
||||
])),
|
||||
]));
|
||||
|
|
|
@ -49,7 +49,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
describe('create', () => {
|
||||
it('should create elements without parents', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 0, 'span')
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span')
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
expect(getDOM().nodeName(rootNodes[0]).toLowerCase()).toBe('span');
|
||||
|
@ -57,16 +57,16 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should create views with multiple root elements', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 0, 'span'),
|
||||
elementDef(NodeFlags.None, null, 0, 'span')
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span')
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should create elements with parents', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, 0, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span'),
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
const spanEl = getDOM().childNodes(rootNodes[0])[0];
|
||||
|
@ -75,7 +75,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should set fixed attributes', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 0, 'div', {'title': 'a'}),
|
||||
elementDef(NodeFlags.None, null, null, 0, 'div', {'title': 'a'}),
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
expect(getDOM().getAttribute(rootNodes[0], 'title')).toBe('a');
|
||||
|
@ -85,7 +85,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
it('should add debug information to the renderer', () => {
|
||||
const someContext = new Object();
|
||||
const {view, rootNodes} = createAndGetRootNodes(
|
||||
compViewDef([elementDef(NodeFlags.None, null, 0, 'div')]), someContext);
|
||||
compViewDef([elementDef(NodeFlags.None, null, null, 0, 'div')]), someContext);
|
||||
expect(getDebugNode(rootNodes[0]).nativeNode).toBe(asElementData(view, 0).renderElement);
|
||||
});
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(
|
||||
NodeFlags.None, null, 0, 'input', null,
|
||||
NodeFlags.None, null, null, 0, 'input', null,
|
||||
[
|
||||
[BindingType.ElementProperty, 'title', SecurityContext.NONE],
|
||||
[BindingType.ElementProperty, 'value', SecurityContext.NONE]
|
||||
|
@ -128,7 +128,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(
|
||||
NodeFlags.None, null, 0, 'div', null,
|
||||
NodeFlags.None, null, null, 0, 'div', null,
|
||||
[
|
||||
[BindingType.ElementAttribute, 'a1', SecurityContext.NONE],
|
||||
[BindingType.ElementAttribute, 'a2', SecurityContext.NONE]
|
||||
|
@ -154,7 +154,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(
|
||||
NodeFlags.None, null, 0, 'div', null,
|
||||
NodeFlags.None, null, null, 0, 'div', null,
|
||||
[[BindingType.ElementClass, 'c1'], [BindingType.ElementClass, 'c2']]),
|
||||
],
|
||||
(view) => {
|
||||
|
@ -177,7 +177,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(
|
||||
NodeFlags.None, null, 0, 'div', null,
|
||||
NodeFlags.None, null, null, 0, 'div', null,
|
||||
[
|
||||
[BindingType.ElementStyle, 'width', 'px'],
|
||||
[BindingType.ElementStyle, 'color', null]
|
||||
|
@ -226,7 +226,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
const removeListenerSpy =
|
||||
spyOn(HTMLElement.prototype, 'removeEventListener').and.callThrough();
|
||||
const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef(
|
||||
[elementDef(NodeFlags.None, null, 0, 'button', null, null, ['click'])], null,
|
||||
[elementDef(NodeFlags.None, null, null, 0, 'button', null, null, ['click'])], null,
|
||||
handleEventSpy));
|
||||
|
||||
rootNodes[0].click();
|
||||
|
@ -249,7 +249,8 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
const removeListenerSpy = spyOn(window, 'removeEventListener');
|
||||
const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef(
|
||||
[elementDef(
|
||||
NodeFlags.None, null, 0, 'button', null, null, [['window', 'windowClick']])],
|
||||
NodeFlags.None, null, null, 0, 'button', null, null,
|
||||
[['window', 'windowClick']])],
|
||||
null, handleEventSpy));
|
||||
|
||||
expect(addListenerSpy).toHaveBeenCalled();
|
||||
|
@ -274,7 +275,8 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
const removeListenerSpy = spyOn(document, 'removeEventListener');
|
||||
const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef(
|
||||
[elementDef(
|
||||
NodeFlags.None, null, 0, 'button', null, null, [['document', 'documentClick']])],
|
||||
NodeFlags.None, null, null, 0, 'button', null, null,
|
||||
[['document', 'documentClick']])],
|
||||
null, handleEventSpy));
|
||||
|
||||
expect(addListenerSpy).toHaveBeenCalled();
|
||||
|
@ -298,7 +300,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
let preventDefaultSpy: jasmine.Spy;
|
||||
|
||||
const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef(
|
||||
[elementDef(NodeFlags.None, null, 0, 'button', null, null, ['click'])], null,
|
||||
[elementDef(NodeFlags.None, null, null, 0, 'button', null, null, ['click'])], null,
|
||||
(view, index, eventName, event) => {
|
||||
preventDefaultSpy = spyOn(event, 'preventDefault').and.callThrough();
|
||||
return eventHandlerResult;
|
||||
|
@ -324,7 +326,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
it('should report debug info on event errors', () => {
|
||||
const addListenerSpy = spyOn(HTMLElement.prototype, 'addEventListener').and.callThrough();
|
||||
const {view, rootNodes} = createAndAttachAndGetRootNodes(compViewDef(
|
||||
[elementDef(NodeFlags.None, null, 0, 'button', null, null, ['click'])], null,
|
||||
[elementDef(NodeFlags.None, null, null, 0, 'button', null, null, ['click'])], null,
|
||||
() => { throw new Error('Test'); }));
|
||||
|
||||
let err: any;
|
||||
|
|
|
@ -56,9 +56,10 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
const {view: parentView, rootNodes} = createAndGetRootNodes(
|
||||
compViewDef([
|
||||
elementDef(NodeFlags.None, null, 2, 'div'),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, 0, embeddedViewDef([elementDef(
|
||||
NodeFlags.None, null, 0, 'span')])),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'div'),
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, null, 0,
|
||||
embeddedViewDef([elementDef(NodeFlags.None, null, null, 0, 'span')])),
|
||||
]),
|
||||
parentContext);
|
||||
|
||||
|
@ -69,13 +70,13 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should attach and detach embedded views', () => {
|
||||
const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 2, 'div'),
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 0,
|
||||
embeddedViewDef([elementDef(NodeFlags.None, null, 0, 'span', {'name': 'child0'})])),
|
||||
anchorDef(
|
||||
NodeFlags.None, null, 0,
|
||||
embeddedViewDef([elementDef(NodeFlags.None, null, 0, 'span', {'name': 'child1'})]))
|
||||
elementDef(NodeFlags.None, null, null, 2, 'div'),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, embeddedViewDef([
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span', {'name': 'child0'})
|
||||
])),
|
||||
anchorDef(NodeFlags.None, null, null, 0, embeddedViewDef([
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span', {'name': 'child1'})
|
||||
]))
|
||||
]));
|
||||
|
||||
const childView0 = createEmbeddedView(parentView, parentView.def.nodes[1]);
|
||||
|
@ -99,10 +100,10 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should include embedded views in root nodes', () => {
|
||||
const {view: parentView} = createAndGetRootNodes(compViewDef([
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 0,
|
||||
embeddedViewDef([elementDef(NodeFlags.None, null, 0, 'span', {'name': 'child0'})])),
|
||||
elementDef(NodeFlags.None, null, 0, 'span', {'name': 'after'})
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, embeddedViewDef([
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span', {'name': 'child0'})
|
||||
])),
|
||||
elementDef(NodeFlags.None, null, null, 0, 'span', {'name': 'after'})
|
||||
]));
|
||||
|
||||
const childView0 = createEmbeddedView(parentView, parentView.def.nodes[0]);
|
||||
|
@ -122,12 +123,12 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
});
|
||||
|
||||
const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 0,
|
||||
NodeFlags.HasEmbeddedViews, null, null, 0,
|
||||
embeddedViewDef(
|
||||
[elementDef(
|
||||
NodeFlags.None, null, 0, 'span', null,
|
||||
NodeFlags.None, null, null, 0, 'span', null,
|
||||
[[BindingType.ElementAttribute, 'name', SecurityContext.NONE]])],
|
||||
update))
|
||||
]));
|
||||
|
@ -160,9 +161,9 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
}
|
||||
|
||||
const {view: parentView, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, 0, embeddedViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0, embeddedViewDef([
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.OnDestroy, null, 0, ChildProvider, [])
|
||||
]))
|
||||
]));
|
||||
|
|
|
@ -0,0 +1,140 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {RenderComponentType, RootRenderer, Sanitizer, SecurityContext, TemplateRef, ViewContainerRef, ViewEncapsulation, getDebugNode} from '@angular/core';
|
||||
import {DebugContext, DefaultServices, NodeDef, NodeFlags, Services, ViewData, ViewDefinition, ViewFlags, ViewHandleEventFn, ViewUpdateFn, anchorDef, asElementData, asProviderData, asTextData, attachEmbeddedView, checkAndUpdateView, checkNoChangesView, checkNodeDynamic, checkNodeInline, createEmbeddedView, createRootView, detachEmbeddedView, elementDef, ngContentDef, providerDef, rootRenderNodes, setCurrentNode, textDef, viewDef} from '@angular/core/src/view/index';
|
||||
import {inject} from '@angular/core/testing';
|
||||
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
|
||||
|
||||
import {isBrowser, setupAndCheckRenderer} from './helper';
|
||||
|
||||
export function main() {
|
||||
if (isBrowser()) {
|
||||
defineTests({directDom: true, viewFlags: ViewFlags.DirectDom});
|
||||
}
|
||||
defineTests({directDom: false, viewFlags: 0});
|
||||
}
|
||||
|
||||
function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
||||
describe(`View NgContent, directDom: ${config.directDom}`, () => {
|
||||
setupAndCheckRenderer(config);
|
||||
|
||||
let services: Services;
|
||||
let renderComponentType: RenderComponentType;
|
||||
|
||||
beforeEach(
|
||||
inject([RootRenderer, Sanitizer], (rootRenderer: RootRenderer, sanitizer: Sanitizer) => {
|
||||
services = new DefaultServices(rootRenderer, sanitizer);
|
||||
renderComponentType =
|
||||
new RenderComponentType('1', 'someUrl', 0, ViewEncapsulation.None, [], {});
|
||||
}));
|
||||
|
||||
function compViewDef(
|
||||
nodes: NodeDef[], update?: ViewUpdateFn, handleEvent?: ViewHandleEventFn): ViewDefinition {
|
||||
return viewDef(config.viewFlags, nodes, update, handleEvent, renderComponentType);
|
||||
}
|
||||
|
||||
function embeddedViewDef(nodes: NodeDef[], update?: ViewUpdateFn): ViewDefinition {
|
||||
return viewDef(config.viewFlags, nodes, update);
|
||||
}
|
||||
|
||||
function hostElDef(contentNodes: NodeDef[], viewNodes: NodeDef[]): NodeDef[] {
|
||||
class AComp {}
|
||||
|
||||
const aCompViewDef = compViewDef(viewNodes);
|
||||
|
||||
return [
|
||||
elementDef(NodeFlags.None, null, null, 1 + contentNodes.length, 'acomp'),
|
||||
providerDef(NodeFlags.None, null, 0, AComp, [], null, null, () => aCompViewDef),
|
||||
...contentNodes
|
||||
];
|
||||
}
|
||||
|
||||
function createAndGetRootNodes(
|
||||
viewDef: ViewDefinition, ctx?: any): {rootNodes: any[], view: ViewData} {
|
||||
const view = createRootView(services, () => viewDef, ctx || {});
|
||||
const rootNodes = rootRenderNodes(view);
|
||||
return {rootNodes, view};
|
||||
}
|
||||
|
||||
it('should create ng-content nodes without parents', () => {
|
||||
const {view, rootNodes} = createAndGetRootNodes(
|
||||
compViewDef(hostElDef([textDef(0, ['a'])], [ngContentDef(null, 0)])));
|
||||
|
||||
expect(getDOM().firstChild(rootNodes[0])).toBe(asTextData(view, 2).renderText);
|
||||
});
|
||||
|
||||
it('should create views with multiple root ng-content nodes', () => {
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef(
|
||||
[textDef(0, ['a']), textDef(1, ['b'])], [ngContentDef(null, 0), ngContentDef(null, 1)])));
|
||||
|
||||
expect(getDOM().childNodes(rootNodes[0])[0]).toBe(asTextData(view, 2).renderText);
|
||||
expect(getDOM().childNodes(rootNodes[0])[1]).toBe(asTextData(view, 3).renderText);
|
||||
});
|
||||
|
||||
it('should create ng-content nodes with parents', () => {
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef(
|
||||
[textDef(0, ['a'])],
|
||||
[elementDef(NodeFlags.None, null, null, 1, 'div'), ngContentDef(null, 0)])));
|
||||
|
||||
expect(getDOM().firstChild(getDOM().firstChild(rootNodes[0])))
|
||||
.toBe(asTextData(view, 2).renderText);
|
||||
});
|
||||
|
||||
it('should reproject ng-content nodes', () => {
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
hostElDef([textDef(0, ['a'])], hostElDef([ngContentDef(0, 0)], [
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'), ngContentDef(null, 0)
|
||||
]))));
|
||||
expect(getDOM().firstChild(getDOM().firstChild(getDOM().firstChild(rootNodes[0]))))
|
||||
.toBe(asTextData(view, 2).renderText);
|
||||
});
|
||||
|
||||
it('should project already attached embedded views', () => {
|
||||
class CreateViewService {
|
||||
constructor(templateRef: TemplateRef<any>, viewContainerRef: ViewContainerRef) {
|
||||
viewContainerRef.createEmbeddedView(templateRef);
|
||||
}
|
||||
}
|
||||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef(
|
||||
[
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 0, 1, embeddedViewDef([textDef(null, ['a'])])),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, CreateViewService, [TemplateRef, ViewContainerRef])
|
||||
],
|
||||
[elementDef(NodeFlags.None, null, null, 1, 'div'), ngContentDef(null, 0)])));
|
||||
|
||||
const anchor = asElementData(view, 2);
|
||||
expect((getDOM().childNodes(getDOM().firstChild(rootNodes[0]))[0]))
|
||||
.toBe(anchor.renderElement);
|
||||
const embeddedView = anchor.embeddedViews[0];
|
||||
expect((getDOM().childNodes(getDOM().firstChild(rootNodes[0]))[1]))
|
||||
.toBe(asTextData(embeddedView, 0).renderText);
|
||||
});
|
||||
|
||||
it('should include projected nodes when attaching / detaching embedded views', () => {
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(hostElDef([textDef(0, ['a'])], [
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, 0, 0, embeddedViewDef([ngContentDef(null, 0)])),
|
||||
])));
|
||||
|
||||
const componentView = asProviderData(view, 1).componentView;
|
||||
const view0 = createEmbeddedView(componentView, componentView.def.nodes[1]);
|
||||
|
||||
attachEmbeddedView(asElementData(componentView, 1), 0, view0);
|
||||
expect(getDOM().childNodes(getDOM().firstChild(rootNodes[0])).length).toBe(2);
|
||||
expect(getDOM().childNodes(getDOM().firstChild(rootNodes[0]))[1])
|
||||
.toBe(asTextData(view, 2).renderText);
|
||||
|
||||
detachEmbeddedView(asElementData(componentView, 1), 0);
|
||||
expect(getDOM().childNodes(getDOM().firstChild(rootNodes[0])).length).toBe(1);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -57,7 +57,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
}
|
||||
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [])
|
||||
]));
|
||||
|
||||
|
@ -72,7 +72,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
let err: any;
|
||||
try {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [])
|
||||
]));
|
||||
} catch (e) {
|
||||
|
@ -98,7 +98,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should inject deps from the same element', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, Dep, []),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [Dep])
|
||||
]));
|
||||
|
@ -108,9 +108,9 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should inject deps from a parent element', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 3, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 3, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, Dep, []),
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [Dep])
|
||||
]));
|
||||
|
||||
|
@ -119,9 +119,9 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should not inject deps from sibling root elements', () => {
|
||||
const nodes = [
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, Dep, []),
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [Dep])
|
||||
];
|
||||
|
||||
|
@ -132,17 +132,17 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
// non root elements
|
||||
expect(
|
||||
() => createAndGetRootNodes(
|
||||
compViewDef([elementDef(NodeFlags.None, null, 4, 'span')].concat(nodes))))
|
||||
compViewDef([elementDef(NodeFlags.None, null, null, 4, 'span')].concat(nodes))))
|
||||
.toThrowError('No provider for Dep!');
|
||||
});
|
||||
|
||||
it('should inject from a parent elment in a parent view', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, Dep, [], null, null,
|
||||
() => compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [Dep])
|
||||
])),
|
||||
]));
|
||||
|
@ -153,7 +153,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
describe('builtin tokens', () => {
|
||||
it('should inject ViewContainerRef', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, 1),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 1),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [ViewContainerRef])
|
||||
]));
|
||||
|
||||
|
@ -162,8 +162,8 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should inject TemplateRef', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
anchorDef(
|
||||
NodeFlags.None, null, 1, embeddedViewDef([anchorDef(NodeFlags.None, null, 0)])),
|
||||
anchorDef(NodeFlags.None, null, null, 1, embeddedViewDef([anchorDef(
|
||||
NodeFlags.None, null, null, 0)])),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [TemplateRef])
|
||||
]));
|
||||
|
||||
|
@ -172,7 +172,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
it('should inject ElementRef', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [ElementRef])
|
||||
]));
|
||||
|
||||
|
@ -182,7 +182,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
if (config.directDom) {
|
||||
it('should not inject Renderer when using directDom', () => {
|
||||
expect(() => createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [Renderer])
|
||||
])))
|
||||
.toThrowError('No provider for Renderer!');
|
||||
|
@ -190,7 +190,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
} else {
|
||||
it('should inject Renderer when not using directDom', () => {
|
||||
createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [Renderer])
|
||||
]));
|
||||
|
||||
|
@ -216,7 +216,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomeService, [], {a: [0, 'a'], b: [1, 'b']})
|
||||
],
|
||||
(view) => {
|
||||
|
@ -257,7 +257,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, SomeService, [], null, {emitter: 'someEventName'})
|
||||
],
|
||||
|
@ -279,7 +279,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, SomeService, [], null, {emitter: 'someEventName'})
|
||||
],
|
||||
|
@ -324,9 +324,9 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
NodeFlags.AfterViewChecked | NodeFlags.OnDestroy;
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 3, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 3, 'span'),
|
||||
providerDef(allFlags, null, 0, SomeService, [], {a: [0, 'a']}),
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(allFlags, null, 0, SomeService, [], {a: [0, 'a']})
|
||||
],
|
||||
(updater) => {
|
||||
|
@ -385,7 +385,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.OnChanges, null, 0, SomeService, [], {a: [0, 'nonMinifiedA']})
|
||||
],
|
||||
(updater) => {
|
||||
|
@ -408,7 +408,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
}
|
||||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.AfterContentChecked, null, 0, SomeService, [], {a: [0, 'a']}),
|
||||
]));
|
||||
|
||||
|
@ -431,7 +431,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
}
|
||||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.OnDestroy, null, 0, SomeService, [], {a: [0, 'a']}),
|
||||
]));
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ export function main() {
|
|||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 2, 'span'), pureArrayDef(2),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'), pureArrayDef(2),
|
||||
providerDef(NodeFlags.None, null, 0, Service, [], {data: [0, 'data']})
|
||||
],
|
||||
(view) => {
|
||||
|
@ -80,7 +80,7 @@ export function main() {
|
|||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 2, 'span'), pureObjectDef(['a', 'b']),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'), pureObjectDef(['a', 'b']),
|
||||
providerDef(NodeFlags.None, null, 0, Service, [], {data: [0, 'data']})
|
||||
],
|
||||
(view) => {
|
||||
|
@ -119,7 +119,7 @@ export function main() {
|
|||
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 3, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 3, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, SomePipe, []), purePipeDef(SomePipe, 2),
|
||||
providerDef(NodeFlags.None, null, 0, Service, [], {data: [0, 'data']})
|
||||
],
|
||||
|
|
|
@ -67,10 +67,10 @@ export function main() {
|
|||
|
||||
it('should query providers on the same element and child elements', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 5, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 5, 'div'),
|
||||
...contentQueryProviders(),
|
||||
aServiceProvider(),
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
aServiceProvider(),
|
||||
]));
|
||||
|
||||
|
@ -87,11 +87,11 @@ export function main() {
|
|||
|
||||
it('should not query providers on sibling or parent elements', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 6, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 6, 'div'),
|
||||
aServiceProvider(),
|
||||
elementDef(NodeFlags.None, null, 2, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'div'),
|
||||
...contentQueryProviders(),
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
aServiceProvider(),
|
||||
]));
|
||||
|
||||
|
@ -105,9 +105,9 @@ export function main() {
|
|||
describe('view queries', () => {
|
||||
it('should query providers in the view', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 2, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'div'),
|
||||
...viewQueryProviders(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
aServiceProvider(),
|
||||
])),
|
||||
]));
|
||||
|
@ -122,9 +122,9 @@ export function main() {
|
|||
|
||||
it('should not query providers on the host element', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 3, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 3, 'div'),
|
||||
...viewQueryProviders(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
])),
|
||||
aServiceProvider(),
|
||||
]));
|
||||
|
@ -138,13 +138,14 @@ export function main() {
|
|||
describe('embedded views', () => {
|
||||
it('should query providers in embedded views', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 5, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 5, 'div'),
|
||||
...contentQueryProviders(),
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 2, viewDef(
|
||||
NodeFlags.HasEmbeddedViews, null, null, 2,
|
||||
viewDef(
|
||||
ViewFlags.None,
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
aServiceProvider(),
|
||||
])),
|
||||
...contentQueryProviders(),
|
||||
|
@ -167,18 +168,19 @@ export function main() {
|
|||
|
||||
it('should query providers in embedded views only at the template declaration', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 3, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 3, 'div'),
|
||||
...contentQueryProviders(),
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 0, viewDef(
|
||||
NodeFlags.HasEmbeddedViews, null, null, 0,
|
||||
viewDef(
|
||||
ViewFlags.None,
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
aServiceProvider(),
|
||||
])),
|
||||
elementDef(NodeFlags.None, null, 3, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 3, 'div'),
|
||||
...contentQueryProviders(),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, 0),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 0),
|
||||
]));
|
||||
|
||||
const childView = createEmbeddedView(view, view.def.nodes[3]);
|
||||
|
@ -199,13 +201,14 @@ export function main() {
|
|||
|
||||
it('should update content queries if embedded views are added or removed', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 3, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 3, 'div'),
|
||||
...contentQueryProviders(),
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 0, viewDef(
|
||||
NodeFlags.HasEmbeddedViews, null, null, 0,
|
||||
viewDef(
|
||||
ViewFlags.None,
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
aServiceProvider(),
|
||||
])),
|
||||
]));
|
||||
|
@ -229,14 +232,14 @@ export function main() {
|
|||
|
||||
it('should update view queries if embedded views are added or removed', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 2, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'div'),
|
||||
...viewQueryProviders(compViewDef([
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 0,
|
||||
NodeFlags.HasEmbeddedViews, null, null, 0,
|
||||
viewDef(
|
||||
ViewFlags.None,
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
aServiceProvider(),
|
||||
])),
|
||||
])),
|
||||
|
@ -268,7 +271,7 @@ export function main() {
|
|||
}
|
||||
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 4, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 4, 'div'),
|
||||
providerDef(NodeFlags.None, null, 1, QueryService, []),
|
||||
queryDef(NodeFlags.HasContentQuery, 'query1', {'a': QueryBindingType.All}),
|
||||
aServiceProvider(),
|
||||
|
@ -291,7 +294,7 @@ export function main() {
|
|||
}
|
||||
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 4, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 4, 'div'),
|
||||
providerDef(NodeFlags.None, null, 1, QueryService, []),
|
||||
queryDef(NodeFlags.HasContentQuery, 'query1', {'a': QueryBindingType.First}),
|
||||
aServiceProvider(),
|
||||
|
@ -312,7 +315,7 @@ export function main() {
|
|||
}
|
||||
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, [['query1', QueryValueType.ElementRef]], 2, 'div'),
|
||||
elementDef(NodeFlags.None, [['query1', QueryValueType.ElementRef]], null, 2, 'div'),
|
||||
providerDef(NodeFlags.None, null, 1, QueryService, []),
|
||||
queryDef(NodeFlags.HasContentQuery, 'query1', {'a': QueryBindingType.First}),
|
||||
]));
|
||||
|
@ -330,8 +333,8 @@ export function main() {
|
|||
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
anchorDef(
|
||||
NodeFlags.None, [['query1', QueryValueType.TemplateRef]], 2,
|
||||
viewDef(ViewFlags.None, [anchorDef(NodeFlags.None, null, 0)])),
|
||||
NodeFlags.None, [['query1', QueryValueType.TemplateRef]], null, 2,
|
||||
viewDef(ViewFlags.None, [anchorDef(NodeFlags.None, null, null, 0)])),
|
||||
providerDef(NodeFlags.None, null, 1, QueryService, []),
|
||||
queryDef(NodeFlags.HasContentQuery, 'query1', {'a': QueryBindingType.First}),
|
||||
]));
|
||||
|
@ -348,7 +351,7 @@ export function main() {
|
|||
}
|
||||
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
anchorDef(NodeFlags.None, [['query1', QueryValueType.ViewContainerRef]], 2),
|
||||
anchorDef(NodeFlags.None, [['query1', QueryValueType.ViewContainerRef]], null, 2),
|
||||
providerDef(NodeFlags.None, null, 1, QueryService, []),
|
||||
queryDef(NodeFlags.HasContentQuery, 'query1', {'a': QueryBindingType.First}),
|
||||
]));
|
||||
|
@ -363,13 +366,14 @@ export function main() {
|
|||
describe('general binding behavior', () => {
|
||||
it('should checkNoChanges', () => {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 4, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 4, 'div'),
|
||||
...contentQueryProviders(),
|
||||
anchorDef(
|
||||
NodeFlags.HasEmbeddedViews, null, 1, viewDef(
|
||||
NodeFlags.HasEmbeddedViews, null, null, 1,
|
||||
viewDef(
|
||||
ViewFlags.None,
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
aServiceProvider(),
|
||||
])),
|
||||
]));
|
||||
|
@ -401,7 +405,7 @@ export function main() {
|
|||
}
|
||||
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 3, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 3, 'div'),
|
||||
providerDef(NodeFlags.None, null, 1, QueryService, []),
|
||||
queryDef(NodeFlags.HasContentQuery, 'query1', {'a': QueryBindingType.All}),
|
||||
aServiceProvider(),
|
||||
|
|
|
@ -44,12 +44,12 @@ export function main() {
|
|||
|
||||
function createViewWithData() {
|
||||
const {view} = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, AComp, [], null, null,
|
||||
() => compViewDef([
|
||||
elementDef(NodeFlags.None, [['#ref', QueryValueType.ElementRef]], 2, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, AService, []), textDef(['a'])
|
||||
elementDef(NodeFlags.None, [['#ref', QueryValueType.ElementRef]], null, 2, 'span'),
|
||||
providerDef(NodeFlags.None, null, 0, AService, []), textDef(null, ['a'])
|
||||
])),
|
||||
]));
|
||||
return view;
|
||||
|
|
|
@ -48,21 +48,22 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
|
||||
describe('create', () => {
|
||||
it('should create text nodes without parents', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([textDef(['a'])])).rootNodes;
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([textDef(null, ['a'])])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
expect(getDOM().getText(rootNodes[0])).toBe('a');
|
||||
});
|
||||
|
||||
it('should create views with multiple root text nodes', () => {
|
||||
const rootNodes =
|
||||
createAndGetRootNodes(compViewDef([textDef(['a']), textDef(['b'])])).rootNodes;
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
textDef(null, ['a']), textDef(null, ['b'])
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(2);
|
||||
});
|
||||
|
||||
it('should create text nodes with parents', () => {
|
||||
const rootNodes = createAndGetRootNodes(compViewDef([
|
||||
elementDef(NodeFlags.None, null, 1, 'div'),
|
||||
textDef(['a']),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'div'),
|
||||
textDef(null, ['a']),
|
||||
])).rootNodes;
|
||||
expect(rootNodes.length).toBe(1);
|
||||
const textNode = getDOM().firstChild(rootNodes[0]);
|
||||
|
@ -73,7 +74,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
it('should add debug information to the renderer', () => {
|
||||
const someContext = new Object();
|
||||
const {view, rootNodes} =
|
||||
createAndGetRootNodes(compViewDef([textDef(['a'])]), someContext);
|
||||
createAndGetRootNodes(compViewDef([textDef(null, ['a'])]), someContext);
|
||||
expect(getDebugNode(rootNodes[0]).nativeNode).toBe(asTextData(view, 0).renderText);
|
||||
});
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ function defineTests(config: {directDom: boolean, viewFlags: number}) {
|
|||
it(`should update ${InlineDynamic[inlineDynamic]}`, () => {
|
||||
const {view, rootNodes} = createAndGetRootNodes(compViewDef(
|
||||
[
|
||||
textDef(['0', '1', '2']),
|
||||
textDef(null, ['0', '1', '2']),
|
||||
],
|
||||
(view: ViewData) => {
|
||||
setCurrentNode(view, 0);
|
||||
|
|
|
@ -17,8 +17,8 @@ export function main() {
|
|||
|
||||
it('should reverse child order for root nodes', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
textDef(['a']), // level 0, index 0
|
||||
textDef(['a']), // level 0, index 0
|
||||
textDef(null, ['a']), // level 0, index 0
|
||||
textDef(null, ['a']), // level 0, index 0
|
||||
]);
|
||||
|
||||
expect(reverseChildOrder(vd)).toEqual([1, 0]);
|
||||
|
@ -26,9 +26,9 @@ export function main() {
|
|||
|
||||
it('should reverse child order for one level, one root', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 2, 'span'), // level 0, index 0
|
||||
textDef(['a']), // level 1, index 1
|
||||
textDef(['a']), // level 1, index 2
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'), // level 0, index 0
|
||||
textDef(null, ['a']), // level 1, index 1
|
||||
textDef(null, ['a']), // level 1, index 2
|
||||
]);
|
||||
|
||||
expect(reverseChildOrder(vd)).toEqual([0, 2, 1]);
|
||||
|
@ -36,11 +36,11 @@ export function main() {
|
|||
|
||||
it('should reverse child order for 1 level, 2 roots', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 2, 'span'), // level 0, index 0
|
||||
textDef(['a']), // level 1, index 1
|
||||
textDef(['a']), // level 1, index 2
|
||||
elementDef(NodeFlags.None, null, 1, 'span'), // level 0, index 3
|
||||
textDef(['a']), // level 1, index 4
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'), // level 0, index 0
|
||||
textDef(null, ['a']), // level 1, index 1
|
||||
textDef(null, ['a']), // level 1, index 2
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'), // level 0, index 3
|
||||
textDef(null, ['a']), // level 1, index 4
|
||||
]);
|
||||
|
||||
expect(reverseChildOrder(vd)).toEqual([3, 4, 0, 2, 1]);
|
||||
|
@ -48,11 +48,11 @@ export function main() {
|
|||
|
||||
it('should reverse child order for 2 levels', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 4, 'span'), // level 0, index 0
|
||||
elementDef(NodeFlags.None, null, 1, 'span'), // level 1, index 1
|
||||
textDef(['a']), // level 2, index 2
|
||||
elementDef(NodeFlags.None, null, 1, 'span'), // level 1, index 3
|
||||
textDef(['a']), // level 2, index 4
|
||||
elementDef(NodeFlags.None, null, null, 4, 'span'), // level 0, index 0
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'), // level 1, index 1
|
||||
textDef(null, ['a']), // level 2, index 2
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'), // level 1, index 3
|
||||
textDef(null, ['a']), // level 2, index 4
|
||||
]);
|
||||
|
||||
expect(reverseChildOrder(vd)).toEqual([0, 3, 4, 1, 2]);
|
||||
|
@ -60,14 +60,14 @@ export function main() {
|
|||
|
||||
it('should reverse child order for mixed levels', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
textDef(['a']), // level 0, index 0
|
||||
elementDef(NodeFlags.None, null, 5, 'span'), // level 0, index 1
|
||||
textDef(['a']), // level 1, index 2
|
||||
elementDef(NodeFlags.None, null, 1, 'span'), // level 1, index 3
|
||||
textDef(['a']), // level 2, index 4
|
||||
elementDef(NodeFlags.None, null, 1, 'span'), // level 1, index 5
|
||||
textDef(['a']), // level 2, index 6
|
||||
textDef(['a']), // level 0, index 7
|
||||
textDef(null, ['a']), // level 0, index 0
|
||||
elementDef(NodeFlags.None, null, null, 5, 'span'), // level 0, index 1
|
||||
textDef(null, ['a']), // level 1, index 2
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'), // level 1, index 3
|
||||
textDef(null, ['a']), // level 2, index 4
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'), // level 1, index 5
|
||||
textDef(null, ['a']), // level 2, index 6
|
||||
textDef(null, ['a']), // level 0, index 7
|
||||
]);
|
||||
|
||||
expect(reverseChildOrder(vd)).toEqual([7, 1, 5, 6, 3, 4, 2, 0]);
|
||||
|
@ -81,9 +81,9 @@ export function main() {
|
|||
|
||||
it('should calculate parents for one level', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
textDef(['a']),
|
||||
textDef(['a']),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
textDef(null, ['a']),
|
||||
textDef(null, ['a']),
|
||||
]);
|
||||
|
||||
expect(parents(vd)).toEqual([undefined, 0, 0]);
|
||||
|
@ -91,11 +91,11 @@ export function main() {
|
|||
|
||||
it('should calculate parents for one level, multiple roots', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
textDef(['a']),
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
textDef(['a']),
|
||||
textDef(['a']),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
textDef(null, ['a']),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
textDef(null, ['a']),
|
||||
textDef(null, ['a']),
|
||||
]);
|
||||
|
||||
expect(parents(vd)).toEqual([undefined, 0, undefined, 2, undefined]);
|
||||
|
@ -103,12 +103,12 @@ export function main() {
|
|||
|
||||
it('should calculate parents for multiple levels', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
textDef(['a']),
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
textDef(['a']),
|
||||
textDef(['a']),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
textDef(null, ['a']),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
textDef(null, ['a']),
|
||||
textDef(null, ['a']),
|
||||
]);
|
||||
|
||||
expect(parents(vd)).toEqual([undefined, 0, 1, undefined, 3, undefined]);
|
||||
|
@ -123,7 +123,7 @@ export function main() {
|
|||
|
||||
it('should calculate childFlags for one level', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.AfterContentChecked, null, 0, AService, [])
|
||||
]);
|
||||
|
||||
|
@ -132,7 +132,8 @@ export function main() {
|
|||
|
||||
it('should calculate childFlags for two levels', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 2, 'span'), elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.AfterContentChecked, null, 0, AService, [])
|
||||
]);
|
||||
|
||||
|
@ -143,9 +144,9 @@ export function main() {
|
|||
|
||||
it('should calculate childFlags for one level, multiple roots', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.AfterContentChecked, null, 0, AService, []),
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
providerDef(NodeFlags.AfterContentInit, null, 0, AService, []),
|
||||
providerDef(NodeFlags.AfterViewChecked, null, 0, AService, []),
|
||||
]);
|
||||
|
@ -158,10 +159,10 @@ export function main() {
|
|||
|
||||
it('should calculate childFlags for multiple levels', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.AfterContentChecked, null, 0, AService, []),
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
providerDef(NodeFlags.AfterContentInit, null, 0, AService, []),
|
||||
providerDef(NodeFlags.AfterViewInit, null, 0, AService, []),
|
||||
]);
|
||||
|
@ -180,7 +181,7 @@ export function main() {
|
|||
|
||||
it('should calculate childMatchedQueries for one level', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, [['q1', QueryValueType.Provider]], 0, AService, [])
|
||||
]);
|
||||
|
||||
|
@ -189,7 +190,8 @@ export function main() {
|
|||
|
||||
it('should calculate childMatchedQueries for two levels', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 2, 'span'), elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, [['q1', QueryValueType.Provider]], 0, AService, [])
|
||||
]);
|
||||
|
||||
|
@ -198,9 +200,9 @@ export function main() {
|
|||
|
||||
it('should calculate childMatchedQueries for one level, multiple roots', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, [['q1', QueryValueType.Provider]], 0, AService, []),
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
providerDef(NodeFlags.None, [['q2', QueryValueType.Provider]], 0, AService, []),
|
||||
providerDef(NodeFlags.None, [['q3', QueryValueType.Provider]], 0, AService, []),
|
||||
]);
|
||||
|
@ -210,10 +212,10 @@ export function main() {
|
|||
|
||||
it('should calculate childMatchedQueries for multiple levels', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
providerDef(NodeFlags.None, [['q1', QueryValueType.Provider]], 0, AService, []),
|
||||
elementDef(NodeFlags.None, null, 2, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 2, 'span'),
|
||||
providerDef(NodeFlags.None, [['q2', QueryValueType.Provider]], 0, AService, []),
|
||||
providerDef(NodeFlags.None, [['q3', QueryValueType.Provider]], 0, AService, []),
|
||||
]);
|
||||
|
@ -223,13 +225,13 @@ export function main() {
|
|||
|
||||
it('should included embedded views into childMatchedQueries', () => {
|
||||
const vd = viewDef(ViewFlags.None, [
|
||||
elementDef(NodeFlags.None, null, 1, 'span'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'span'),
|
||||
anchorDef(
|
||||
NodeFlags.None, null, 0,
|
||||
NodeFlags.None, null, null, 0,
|
||||
viewDef(
|
||||
ViewFlags.None,
|
||||
[
|
||||
elementDef(NodeFlags.None, [['q1', QueryValueType.Provider]], 1, 'span'),
|
||||
elementDef(NodeFlags.None, [['q1', QueryValueType.Provider]], null, 1, 'span'),
|
||||
]))
|
||||
]);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ let viewFlags = ViewFlags.DirectDom;
|
|||
|
||||
function TreeComponent_Host(): ViewDefinition {
|
||||
return viewDef(viewFlags, [
|
||||
elementDef(NodeFlags.None, null, 1, 'tree'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'tree'),
|
||||
providerDef(NodeFlags.None, null, 0, TreeComponent, [], null, null, TreeComponent_0),
|
||||
]);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ function TreeComponent_0(): ViewDefinition {
|
|||
const TreeComponent_1: ViewDefinition = viewDef(
|
||||
viewFlags,
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'tree'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'tree'),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, TreeComponent, [], {data: [0, 'data']}, null, TreeComponent_0),
|
||||
],
|
||||
|
@ -47,7 +47,7 @@ function TreeComponent_0(): ViewDefinition {
|
|||
const TreeComponent_2: ViewDefinition = viewDef(
|
||||
viewFlags,
|
||||
[
|
||||
elementDef(NodeFlags.None, null, 1, 'tree'),
|
||||
elementDef(NodeFlags.None, null, null, 1, 'tree'),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, TreeComponent, [], {data: [0, 'data']}, null, TreeComponent_0),
|
||||
],
|
||||
|
@ -61,13 +61,13 @@ function TreeComponent_0(): ViewDefinition {
|
|||
viewFlags,
|
||||
[
|
||||
elementDef(
|
||||
NodeFlags.None, null, 1, 'span', null,
|
||||
NodeFlags.None, null, null, 1, 'span', null,
|
||||
[[BindingType.ElementStyle, 'backgroundColor', null]]),
|
||||
textDef([' ', ' ']),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, 1, TreeComponent_1),
|
||||
textDef(null, [' ', ' ']),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 1, TreeComponent_1),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, NgIf, [ViewContainerRef, TemplateRef], {ngIf: [0, 'ngIf']}),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, 1, TreeComponent_2),
|
||||
anchorDef(NodeFlags.HasEmbeddedViews, null, null, 1, TreeComponent_2),
|
||||
providerDef(
|
||||
NodeFlags.None, null, 0, NgIf, [ViewContainerRef, TemplateRef], {ngIf: [0, 'ngIf']}),
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue