2019-08-12 08:41:52 -04:00
|
|
|
/**
|
|
|
|
* @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
|
|
|
|
*/
|
2019-10-22 23:18:48 -04:00
|
|
|
import {addToViewTree, createLContainer, createLView, createTNode, createTView, getOrCreateTNode, refreshView, renderView} from '../../../src/render3/instructions/shared';
|
2019-08-12 06:31:15 -04:00
|
|
|
import {ComponentTemplate} from '../../../src/render3/interfaces/definition';
|
2019-09-23 14:08:51 -04:00
|
|
|
import {TAttributes, TNodeType, TViewNode} from '../../../src/render3/interfaces/node';
|
2019-10-22 23:16:28 -04:00
|
|
|
import {RendererFactory3, domRendererFactory3} from '../../../src/render3/interfaces/renderer';
|
2019-10-28 15:08:17 -04:00
|
|
|
import {LView, LViewFlags, TView, TViewType} from '../../../src/render3/interfaces/view';
|
2019-08-12 06:31:15 -04:00
|
|
|
import {insertView} from '../../../src/render3/node_manipulation';
|
|
|
|
|
2019-10-24 23:28:11 -04:00
|
|
|
import {MicroBenchmarkRendererFactory} from './noop_renderer';
|
2019-10-22 23:16:28 -04:00
|
|
|
|
|
|
|
const isBrowser = typeof process === 'undefined';
|
2019-10-24 23:28:11 -04:00
|
|
|
const rendererFactory: RendererFactory3 =
|
|
|
|
isBrowser ? domRendererFactory3 : new MicroBenchmarkRendererFactory;
|
2019-10-22 23:16:28 -04:00
|
|
|
const renderer = rendererFactory.createRenderer(null, null);
|
2019-08-12 06:31:15 -04:00
|
|
|
|
2019-08-27 08:44:16 -04:00
|
|
|
export function createAndRenderLView(
|
|
|
|
parentLView: LView | null, tView: TView, hostTNode: TViewNode) {
|
|
|
|
const embeddedLView = createLView(
|
2019-10-22 23:16:28 -04:00
|
|
|
parentLView, tView, {}, LViewFlags.CheckAlways, null, hostTNode, rendererFactory, renderer);
|
2019-08-27 08:44:16 -04:00
|
|
|
renderView(embeddedLView, tView, null);
|
|
|
|
}
|
|
|
|
|
2019-08-12 06:31:15 -04:00
|
|
|
export function setupRootViewWithEmbeddedViews(
|
2019-09-23 14:08:51 -04:00
|
|
|
templateFn: ComponentTemplate<any>| null, decls: number, vars: number, noOfViews: number,
|
|
|
|
embeddedViewContext: any = {}, consts: TAttributes[] | null = null): LView {
|
2019-10-22 23:18:48 -04:00
|
|
|
return setupTestHarness(templateFn, decls, vars, noOfViews, embeddedViewContext, consts)
|
|
|
|
.hostLView;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface TestHarness {
|
|
|
|
hostLView: LView;
|
|
|
|
hostTView: TView;
|
|
|
|
embeddedTView: TView;
|
|
|
|
createEmbeddedLView(): LView;
|
|
|
|
detectChanges(): void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function setupTestHarness(
|
|
|
|
templateFn: ComponentTemplate<any>| null, decls: number, vars: number, noOfViews: number,
|
|
|
|
embeddedViewContext: any = {}, consts: TAttributes[] | null = null): TestHarness {
|
2019-08-12 06:31:15 -04:00
|
|
|
// Create a root view with a container
|
2019-10-28 15:08:17 -04:00
|
|
|
const hostTView = createTView(TViewType.Root, -1, null, 1, 0, null, null, null, null, consts);
|
2019-10-22 23:18:48 -04:00
|
|
|
const tContainerNode = getOrCreateTNode(hostTView, null, 0, TNodeType.Container, null, null);
|
2019-10-22 23:16:28 -04:00
|
|
|
const hostNode = renderer.createElement('div');
|
2019-10-22 23:18:48 -04:00
|
|
|
const hostLView = createLView(
|
2019-10-22 23:16:28 -04:00
|
|
|
null, hostTView, {}, LViewFlags.CheckAlways | LViewFlags.IsRoot, hostNode, null,
|
|
|
|
rendererFactory, renderer);
|
|
|
|
const mockRCommentNode = renderer.createComment('');
|
|
|
|
const lContainer =
|
|
|
|
createLContainer(mockRCommentNode, hostLView, mockRCommentNode, tContainerNode, true);
|
2019-10-22 23:18:48 -04:00
|
|
|
addToViewTree(hostLView, lContainer);
|
2019-08-12 06:31:15 -04:00
|
|
|
|
|
|
|
|
|
|
|
// create test embedded views
|
2019-10-28 15:08:17 -04:00
|
|
|
const embeddedTView =
|
|
|
|
createTView(TViewType.Embedded, -1, templateFn, decls, vars, null, null, null, null, consts);
|
2019-10-22 23:18:48 -04:00
|
|
|
const viewTNode = createTNode(hostTView, null, TNodeType.View, -1, null, null) as TViewNode;
|
2019-08-12 06:31:15 -04:00
|
|
|
|
2019-10-22 23:18:48 -04:00
|
|
|
function createEmbeddedLView(): LView {
|
2019-08-12 06:31:15 -04:00
|
|
|
const embeddedLView = createLView(
|
2019-10-22 23:18:48 -04:00
|
|
|
hostLView, embeddedTView, embeddedViewContext, LViewFlags.CheckAlways, null, viewTNode,
|
|
|
|
rendererFactory, renderer);
|
|
|
|
renderView(embeddedLView, embeddedTView, embeddedViewContext);
|
|
|
|
return embeddedLView;
|
|
|
|
}
|
|
|
|
|
|
|
|
function detectChanges(): void {
|
|
|
|
refreshView(hostLView, hostTView, hostTView.template, embeddedViewContext);
|
2019-08-12 06:31:15 -04:00
|
|
|
}
|
|
|
|
|
2019-10-22 23:18:48 -04:00
|
|
|
// create embedded views and add them to the container
|
|
|
|
for (let i = 0; i < noOfViews; i++) {
|
|
|
|
insertView(createEmbeddedLView(), lContainer, i);
|
|
|
|
}
|
2019-08-12 06:31:15 -04:00
|
|
|
|
2019-10-22 23:18:48 -04:00
|
|
|
return {
|
|
|
|
hostLView: hostLView,
|
|
|
|
hostTView: hostTView,
|
|
|
|
embeddedTView: embeddedTView,
|
|
|
|
createEmbeddedLView: createEmbeddedLView,
|
|
|
|
detectChanges: detectChanges,
|
|
|
|
};
|
2019-09-23 14:08:51 -04:00
|
|
|
}
|