fix(view): remove dynamic components when the parent view is dehydrated

Also adds a bunch of unit tests for affected parts.

Fixes #1201
This commit is contained in:
Tobias Bosch
2015-04-14 18:01:44 -07:00
parent 6ecaa9aebb
commit 213dabdceb
16 changed files with 813 additions and 117 deletions

View File

@ -1,3 +1,4 @@
import {isBlank, isPresent} from 'angular2/src/facade/lang';
import {AST} from 'angular2/change_detection';
import {SetterFn} from 'angular2/src/reflection/types';
import {List, ListWrapper} from 'angular2/src/facade/collection';
@ -38,6 +39,14 @@ export class ElementBinder {
this.distanceToParent = distanceToParent;
this.propertySetters = propertySetters;
}
hasStaticComponent() {
return isPresent(this.componentId) && isPresent(this.nestedProtoView);
}
hasDynamicComponent() {
return isPresent(this.componentId) && isBlank(this.nestedProtoView);
}
}
export class Event {

View File

@ -165,6 +165,11 @@ export class RenderView {
var cv = this.componentChildViews[i];
if (isPresent(cv)) {
cv.dehydrate();
if (this.proto.elementBinders[i].hasDynamicComponent()) {
ViewContainer.removeViewNodes(cv);
this.lightDoms[i] = null;
this.componentChildViews[i] = null;
}
}
}

View File

@ -84,7 +84,6 @@ export class ViewFactory {
} else {
viewRootNodes = [rootElementClone];
}
var binders = protoView.elementBinders;
var boundTextNodes = [];
var boundElements = ListWrapper.createFixedSize(binders.length);
@ -133,7 +132,7 @@ export class ViewFactory {
var element = boundElements[binderIdx];
// static child components
if (isPresent(binder.componentId) && isPresent(binder.nestedProtoView)) {
if (binder.hasStaticComponent()) {
var childView = this._createView(binder.nestedProtoView);
view.setComponentView(this._shadowDomStrategy, binderIdx, childView);
}