From 1612985e48c7294305f5d567218b7557f65b55a5 Mon Sep 17 00:00:00 2001 From: Kara Erickson Date: Fri, 16 Mar 2018 18:50:48 -0700 Subject: [PATCH] refactor(ivy): allow tick and deps to be tree-shaken (#22838) PR Close #22838 --- packages/core/src/render3/component.ts | 22 ++++++++++--------- .../hello_world/bundle.golden_symbols.json | 9 -------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/packages/core/src/render3/component.ts b/packages/core/src/render3/component.ts index 08ea0bab9c..4d3bf089c1 100644 --- a/packages/core/src/render3/component.ts +++ b/packages/core/src/render3/component.ts @@ -13,8 +13,9 @@ import {ComponentRef as viewEngine_ComponentRef} from '../linker/component_facto import {assertNotNull} from './assert'; import {queueLifecycleHooks} from './hooks'; -import {CLEAN_PROMISE, _getComponentHostLElementNode, createLView, createTView, directiveCreate, enterView, getDirectiveInstance, getRootView, hostElement, initChangeDetectorIfExisting, leaveView, locateHostElement, scheduleTick, tick} from './instructions'; +import {CLEAN_PROMISE, _getComponentHostLElementNode, createLView, createTView, directiveCreate, enterView, getDirectiveInstance, getRootView, hostElement, initChangeDetectorIfExisting, locateHostElement, renderComponentOrTemplate} from './instructions'; import {ComponentDef, ComponentType} from './interfaces/definition'; +import {LElementNode} from './interfaces/node'; import {RElement, RendererFactory3, domRendererFactory3} from './interfaces/renderer'; import {LView, LViewFlags, RootContext} from './interfaces/view'; import {stringify} from './util'; @@ -123,17 +124,18 @@ export function renderComponent( scheduler: opts.scheduler || requestAnimationFrame, clean: CLEAN_PROMISE, }; - const oldView = enterView( - createLView( - -1, rendererFactory.createRenderer(hostNode, componentDef.rendererType), createTView(), - null, rootContext, componentDef.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways), - null !); + const rootView = createLView( + -1, rendererFactory.createRenderer(hostNode, componentDef.rendererType), createTView(), null, + rootContext, componentDef.onPush ? LViewFlags.Dirty : LViewFlags.CheckAlways); + + const oldView = enterView(rootView, null !); + + let elementNode: LElementNode; try { // Create element node at index 0 in data array - const elementNode = hostElement(hostNode, componentDef); + elementNode = hostElement(hostNode, componentDef); // Create directive instance with n() and store at index 1 in data array (el is 0) - component = rootContext.component = - getDirectiveInstance(directiveCreate(1, componentDef.factory(), componentDef)); + component = rootContext.component = directiveCreate(1, componentDef.factory(), componentDef) as T; initChangeDetectorIfExisting(elementNode.nodeInjector, component); } finally { // We must not use leaveView here because it will set creationMode to false too early, @@ -143,7 +145,7 @@ export function renderComponent( } opts.hostFeatures && opts.hostFeatures.forEach((feature) => feature(component, componentDef)); - tick(component); + renderComponentOrTemplate(elementNode, rootView, component); return component; } diff --git a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json index d133188eff..3409017e0e 100644 --- a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json @@ -32,9 +32,6 @@ { "name": "__window$1" }, - { - "name": "_getComponentHostLElementNode" - }, { "name": "_renderCompCount" }, @@ -116,9 +113,6 @@ { "name": "getOrCreateTView" }, - { - "name": "getRootView" - }, { "name": "getSymbolObservable" }, @@ -206,9 +200,6 @@ { "name": "throwErrorIfNoChangesMode" }, - { - "name": "tick" - }, { "name": "viewAttached" }