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