From fc1b791a7a5dda12bcdd07eca8a828094db03033 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 10 Feb 2015 18:37:47 +0100 Subject: [PATCH] fix(view): ViewPort light should come from the direct parent --- .../src/core/compiler/element_injector.js | 4 +++ modules/angular2/src/core/compiler/view.js | 6 ++--- .../core/compiler/element_injector_spec.js | 20 +++++++++++++++ .../shadow_dom_emulation_integration_spec.js | 25 +++++++++++++++++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/modules/angular2/src/core/compiler/element_injector.js b/modules/angular2/src/core/compiler/element_injector.js index e322513715..d502c8e83e 100644 --- a/modules/angular2/src/core/compiler/element_injector.js +++ b/modules/angular2/src/core/compiler/element_injector.js @@ -261,6 +261,10 @@ export class ProtoElementInjector { return new ElementInjector(this, parent, host, eventCallbacks); } + directParent(): ProtoElementInjector { + return this.distanceToParent < 2 ? this.parent : null; + } + _createBinding(bindingOrType) { if (bindingOrType instanceof DirectiveBinding) { return bindingOrType; diff --git a/modules/angular2/src/core/compiler/view.js b/modules/angular2/src/core/compiler/view.js index 7277e97dd6..b38587ab7e 100644 --- a/modules/angular2/src/core/compiler/view.js +++ b/modules/angular2/src/core/compiler/view.js @@ -401,7 +401,7 @@ export class ProtoView { // viewPorts var viewPort = null; if (isPresent(binder.templateDirective)) { - var destLightDom = this._parentElementLightDom(protoElementInjector, preBuiltObjects); + var destLightDom = this._directParentElementLightDom(protoElementInjector, preBuiltObjects); viewPort = new ViewPort(view, element, binder.nestedProtoView, elementInjector, destLightDom); ListWrapper.push(viewPorts, viewPort); } @@ -456,8 +456,8 @@ export class ProtoView { } } - _parentElementLightDom(protoElementInjector:ProtoElementInjector, preBuiltObjects:List):LightDom { - var p = protoElementInjector.parent; + _directParentElementLightDom(protoElementInjector:ProtoElementInjector, preBuiltObjects:List):LightDom { + var p = protoElementInjector.directParent(); return isPresent(p) ? preBuiltObjects[p.index].lightDom : null; } diff --git a/modules/angular2/test/core/compiler/element_injector_spec.js b/modules/angular2/test/core/compiler/element_injector_spec.js index a0ed9f6fd5..4b094d6a4f 100644 --- a/modules/angular2/test/core/compiler/element_injector_spec.js +++ b/modules/angular2/test/core/compiler/element_injector_spec.js @@ -153,6 +153,26 @@ export function main() { return shadow; } + describe("ProtoElementInjector", () => { + describe("direct parent", () => { + it("should return parent proto injector when distance is 1", () => { + var distance = 1; + var protoParent = new ProtoElementInjector(null, 0, []); + var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance); + + expect(protoChild.directParent()).toEqual(protoParent); + }); + + it("should return null otherwise", () => { + var distance = 2; + var protoParent = new ProtoElementInjector(null, 0, []); + var protoChild = new ProtoElementInjector(protoParent, 1, [], false, distance); + + expect(protoChild.directParent()).toEqual(null); + }); + }); + }); + describe("ElementInjector", function () { describe("instantiate", function () { it("should create an element injector", function () { diff --git a/modules/angular2/test/core/compiler/shadow_dom/shadow_dom_emulation_integration_spec.js b/modules/angular2/test/core/compiler/shadow_dom/shadow_dom_emulation_integration_spec.js index 535fefd3ae..427b68e79c 100644 --- a/modules/angular2/test/core/compiler/shadow_dom/shadow_dom_emulation_integration_spec.js +++ b/modules/angular2/test/core/compiler/shadow_dom/shadow_dom_emulation_integration_spec.js @@ -77,6 +77,31 @@ export function main() { }); }); + it("should redistribute direct child viewports when the light dom changes", (done) => { + var temp = '' + + '
A
' + + '
B
' + + '
'; + + compile(temp, (view, lc) => { + var dir = view.elementInjectors[1].get(ManualTemplateDirective); + + expect(view.nodes).toHaveText('(, B)'); + + dir.show(); + lc.tick(); + + expect(view.nodes).toHaveText('(, AB)'); + + dir.hide(); + lc.tick(); + + expect(view.nodes).toHaveText('(, B)'); + + done(); + }); + }); + it("should redistribute when the light dom changes", (done) => { var temp = '' + '
A
' +