fix(view): fixed view instantiation to use the component template's change detector when creating BindingPropagationConfig

This commit is contained in:
vsavkin 2015-03-23 17:14:12 -07:00
parent c686e7ea30
commit f8e7a37c0d
2 changed files with 52 additions and 19 deletions

View File

@ -449,7 +449,7 @@ export class ProtoView {
lightDom = strategy.constructLightDom(view, childView, element); lightDom = strategy.constructLightDom(view, childView, element);
strategy.attachTemplate(element, childView); strategy.attachTemplate(element, childView);
bindingPropagationConfig = new BindingPropagationConfig(changeDetector); bindingPropagationConfig = new BindingPropagationConfig(childView.changeDetector);
ListWrapper.push(componentChildViews, childView); ListWrapper.push(componentChildViews, childView);
} }

View File

@ -451,7 +451,10 @@ export function main() {
}) })
})); }));
it('should provide binding configuration config to the component', inject([AsyncTestCompleter], (async) => { describe("BindingPropagationConfig", () => {
it("can be used to disable the change detection of the component's template",
inject([AsyncTestCompleter], (async) => {
tplResolver.setTemplate(MyComp, new Template({ tplResolver.setTemplate(MyComp, new Template({
inline: '<push-cmp #cmp></push-cmp>', inline: '<push-cmp #cmp></push-cmp>',
directives: [[[PushBasedComp]]] directives: [[[PushBasedComp]]]
@ -476,6 +479,30 @@ export function main() {
}) })
})); }));
it('should not affect updating properties on the component', inject([AsyncTestCompleter], (async) => {
tplResolver.setTemplate(MyComp, new Template({
inline: '<push-cmp [prop]="ctxProp" #cmp></push-cmp>',
directives: [[[PushBasedComp]]]
}));
compiler.compile(MyComp).then((pv) => {
createView(pv);
var cmp = view.locals.get('cmp');
ctx.ctxProp = "one";
cd.detectChanges();
expect(cmp.prop).toEqual("one");
ctx.ctxProp = "two";
cd.detectChanges();
expect(cmp.prop).toEqual("two");
async.done();
})
}));
});
it('should create a component that injects a @Parent', inject([AsyncTestCompleter], (async) => { it('should create a component that injects a @Parent', inject([AsyncTestCompleter], (async) => {
tplResolver.setTemplate(MyComp, new Template({ tplResolver.setTemplate(MyComp, new Template({
inline: '<some-directive><cmp-with-parent #child></cmp-with-parent></some-directive>', inline: '<some-directive><cmp-with-parent #child></cmp-with-parent></some-directive>',
@ -673,11 +700,17 @@ class MyDir {
} }
} }
@Component({selector: 'push-cmp'}) @Component({
selector: 'push-cmp',
bind: {
'prop': 'prop'
}
})
@Template({inline: '{{field}}'}) @Template({inline: '{{field}}'})
class PushBasedComp { class PushBasedComp {
numberOfChecks:number; numberOfChecks:number;
bpc:BindingPropagationConfig; bpc:BindingPropagationConfig;
prop;
constructor(bpc:BindingPropagationConfig) { constructor(bpc:BindingPropagationConfig) {
this.numberOfChecks = 0; this.numberOfChecks = 0;