test(change_detection): add an integration test verifying that binding propagation config works
This commit is contained in:
parent
234e1eccca
commit
91fd5a69bf
|
@ -2,12 +2,13 @@ export * from './src/core/annotations/annotations';
|
|||
export * from './src/core/annotations/visibility';
|
||||
export * from './src/core/compiler/interfaces';
|
||||
export * from './src/core/annotations/template_config';
|
||||
|
||||
export * from './src/core/application';
|
||||
|
||||
export * from './src/core/compiler/compiler';
|
||||
|
||||
export * from './src/core/compiler/template_loader';
|
||||
export * from './src/core/compiler/view';
|
||||
export * from './src/core/compiler/viewport';
|
||||
export * from './src/core/compiler/binding_propagation_config';
|
||||
|
||||
export * from './src/core/dom/element';
|
||||
|
|
|
@ -51,4 +51,12 @@ export class AbstractChangeDetector extends ChangeDetector {
|
|||
children[i]._detectChanges(throwOnChange);
|
||||
}
|
||||
}
|
||||
|
||||
markPathToRootAsCheckOnce() {
|
||||
var c = this;
|
||||
while(isPresent(c) && c.mode != DETACHED) {
|
||||
if (c.mode === CHECKED) c.mode = CHECK_ONCE;
|
||||
c = c.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -214,12 +214,4 @@ export class ChangeDetectionUtil {
|
|||
}
|
||||
return updatedRecords;
|
||||
}
|
||||
|
||||
static markPathToRootAsCheckOnce(cd:ChangeDetector) {
|
||||
var c = cd;
|
||||
while(isPresent(c) && c.mode != DETACHED) {
|
||||
if (c.mode === CHECKED) c.mode = CHECK_ONCE;
|
||||
c = c.parent;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -535,7 +535,7 @@ export function main() {
|
|||
var checkOnceChild = changeDetector(CHECK_ONCE, checkAlwaysChild);
|
||||
var checkedChild = changeDetector(CHECKED, checkOnceChild);
|
||||
|
||||
ChangeDetectionUtil.markPathToRootAsCheckOnce(checkedChild);
|
||||
checkedChild.markPathToRootAsCheckOnce();
|
||||
|
||||
expect(root.mode).toEqual(CHECK_ALWAYS);
|
||||
expect(disabled.mode).toEqual(DETACHED);
|
||||
|
|
|
@ -9,6 +9,7 @@ import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
|
|||
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
|
||||
import {NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
|
||||
import {TemplateLoader} from 'angular2/src/core/compiler/template_loader';
|
||||
import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config';
|
||||
|
||||
import {Decorator, Component, Template} from 'angular2/src/core/annotations/annotations';
|
||||
import {TemplateConfig} from 'angular2/src/core/annotations/template_config';
|
||||
|
@ -198,6 +199,26 @@ export function main() {
|
|||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it('should provide binding configuration config to the component', (done) => {
|
||||
compiler.compile(MyComp, el('<push-cmp #cmp></push-cmp>')).then((pv) => {
|
||||
createView(pv);
|
||||
|
||||
var cmp = view.contextWithLocals.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);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -214,8 +235,34 @@ class MyDir {
|
|||
}
|
||||
|
||||
@Component({
|
||||
selector: 'push-cmp',
|
||||
template: new TemplateConfig({
|
||||
directives: [MyDir, ChildComp, SomeTemplate]
|
||||
inline: '{{field}}'
|
||||
})
|
||||
})
|
||||
class PushBasedComp {
|
||||
numberOfChecks:number;
|
||||
bpc:BindingPropagationConfig;
|
||||
|
||||
constructor(bpc:BindingPropagationConfig) {
|
||||
this.numberOfChecks = 0;
|
||||
this.bpc = bpc;
|
||||
bpc.shouldBePropagated();
|
||||
}
|
||||
|
||||
get field(){
|
||||
this.numberOfChecks++;
|
||||
return "fixed";
|
||||
}
|
||||
|
||||
propagate() {
|
||||
this.bpc.shouldBePropagatedFromRoot();
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
template: new TemplateConfig({
|
||||
directives: [MyDir, ChildComp, SomeTemplate, PushBasedComp]
|
||||
})
|
||||
})
|
||||
class MyComp {
|
||||
|
|
Loading…
Reference in New Issue