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,30 +451,57 @@ export function main() {
}) })
})); }));
it('should provide binding configuration config to the component', inject([AsyncTestCompleter], (async) => { describe("BindingPropagationConfig", () => {
tplResolver.setTemplate(MyComp, new Template({ it("can be used to disable the change detection of the component's template",
inline: '<push-cmp #cmp></push-cmp>', inject([AsyncTestCompleter], (async) => {
directives: [[[PushBasedComp]]]
tplResolver.setTemplate(MyComp, new Template({
inline: '<push-cmp #cmp></push-cmp>',
directives: [[[PushBasedComp]]]
}));
compiler.compile(MyComp).then((pv) => {
createView(pv);
var cmp = view.locals.get('cmp');
cd.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
cd.detectChanges();
expect(cmp.numberOfChecks).toEqual(1);
cmp.propagate();
cd.detectChanges();
expect(cmp.numberOfChecks).toEqual(2);
async.done();
})
})); }));
compiler.compile(MyComp).then((pv) => { it('should not affect updating properties on the component', inject([AsyncTestCompleter], (async) => {
createView(pv); tplResolver.setTemplate(MyComp, new Template({
inline: '<push-cmp [prop]="ctxProp" #cmp></push-cmp>',
directives: [[[PushBasedComp]]]
}));
var cmp = view.locals.get('cmp'); compiler.compile(MyComp).then((pv) => {
createView(pv);
cd.detectChanges(); var cmp = view.locals.get('cmp');
expect(cmp.numberOfChecks).toEqual(1);
cd.detectChanges(); ctx.ctxProp = "one";
expect(cmp.numberOfChecks).toEqual(1); cd.detectChanges();
expect(cmp.prop).toEqual("one");
cmp.propagate(); ctx.ctxProp = "two";
cd.detectChanges();
expect(cmp.prop).toEqual("two");
cd.detectChanges(); async.done();
expect(cmp.numberOfChecks).toEqual(2); })
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({
@ -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;