From 36648293a8f0edcdaee83c853e197fd4dd1ac73e Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Sun, 29 Jul 2018 14:35:05 -0700 Subject: [PATCH] refactor(ivy): misc (#25174) PR Close #25174 --- packages/core/src/render3/di.ts | 13 ++++++++----- packages/core/src/render3/instructions.ts | 2 +- .../test/bundling/todo/bundle.golden_symbols.json | 8 +++++++- .../core/test/render3/view_container_ref_spec.ts | 15 +++++---------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 9209484bc5..123b2f38f1 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -11,7 +11,7 @@ import {ChangeDetectorRef as viewEngine_ChangeDetectorRef} from '../change_detection/change_detector_ref'; import {InjectionToken} from '../di/injection_token'; -import {InjectFlags, Injector, inject, setCurrentInjector} from '../di/injector'; +import {InjectFlags, Injector, NullInjector, inject, setCurrentInjector} from '../di/injector'; import * as viewEngine from '../linker'; import {Type} from '../type'; @@ -636,20 +636,23 @@ class NodeInjector implements Injector { class ViewContainerRef implements viewEngine.ViewContainerRef { private _viewRefs: viewEngine.ViewRef[] = []; - constructor( private _lContainerNode: LContainerNode, private _hostNode: LElementNode|LContainerNode) {} - get element(): ElementRef { return new ElementRef(this._hostNode.native); } + get element(): ElementRef { + const injector = getOrCreateNodeInjectorForNode(this._hostNode); + return getOrCreateElementRef(injector); + } get injector(): Injector { - return new NodeInjector(getOrCreateNodeInjectorForNode(this._hostNode)); + const injector = getOrCreateNodeInjectorForNode(this._hostNode); + return new NodeInjector(injector); } /** @deprecated No replacement */ get parentInjector(): Injector { const parentLInjector = getParentLNode(this._hostNode).nodeInjector; - return parentLInjector ? new NodeInjector(parentLInjector) : Injector.NULL; + return parentLInjector ? new NodeInjector(parentLInjector) : new NullInjector(); } clear(): void { diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index efeb0fc4b0..228929bc4d 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -336,7 +336,7 @@ export function createLViewData( null, // directives null, // cleanupInstances context, // context - viewData && viewData[INJECTOR] || null, // injector + viewData ? viewData[INJECTOR] : null, // injector renderer, // renderer sanitizer || null, // sanitizer null, // tail diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index da607a5ef7..f0511e71e2 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -26,6 +26,9 @@ { "name": "ChangeDetectionStrategy" }, + { + "name": "ChangeDetectorRef" + }, { "name": "DECLARATION_VIEW" }, @@ -146,6 +149,9 @@ { "name": "TVIEW" }, + { + "name": "TemplateRef" + }, { "name": "TemplateRef$1" }, @@ -180,7 +186,7 @@ "name": "VIEWS" }, { - "name": "ViewContainerRef$1" + "name": "ViewContainerRef" }, { "name": "ViewContainerRef$1" diff --git a/packages/core/test/render3/view_container_ref_spec.ts b/packages/core/test/render3/view_container_ref_spec.ts index c38c72ca39..ca63d40f9a 100644 --- a/packages/core/test/render3/view_container_ref_spec.ts +++ b/packages/core/test/render3/view_container_ref_spec.ts @@ -1039,10 +1039,8 @@ describe('ViewContainerRef', () => { describe('getters', () => { it('should work on elements', () => { function createTemplate() { - elementStart(0, 'header', ['vcref', '']); - elementEnd(); - elementStart(1, 'footer'); - elementEnd(); + element(0, 'header', ['vcref', '']); + element(1, 'footer'); } new TemplateFixture(createTemplate, undefined, [DirectiveWithVCRef]); @@ -1060,10 +1058,8 @@ describe('ViewContainerRef', () => { createComponent('header-cmp', function(rf: RenderFlags, ctx: any) {}); function createTemplate() { - elementStart(0, 'header-cmp', ['vcref', '']); - elementEnd(); - elementStart(1, 'footer'); - elementEnd(); + element(0, 'header-cmp', ['vcref', '']); + element(1, 'footer'); } new TemplateFixture(createTemplate, undefined, [HeaderComponent, DirectiveWithVCRef]); @@ -1079,8 +1075,7 @@ describe('ViewContainerRef', () => { it('should work on containers', () => { function createTemplate() { container(0, embeddedTemplate, undefined, ['vcref', '']); - elementStart(1, 'footer'); - elementEnd(); + element(1, 'footer'); } function updateTemplate() {