Skip to content

Commit 91fd5a6

Browse files
committed
test(change_detection): add an integration test verifying that binding propagation config works
1 parent 234e1ec commit 91fd5a6

File tree

5 files changed

+59
-11
lines changed

5 files changed

+59
-11
lines changed

modules/angular2/core.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ export * from './src/core/annotations/annotations';
22
export * from './src/core/annotations/visibility';
33
export * from './src/core/compiler/interfaces';
44
export * from './src/core/annotations/template_config';
5-
65
export * from './src/core/application';
76

87
export * from './src/core/compiler/compiler';
8+
99
export * from './src/core/compiler/template_loader';
1010
export * from './src/core/compiler/view';
1111
export * from './src/core/compiler/viewport';
12+
export * from './src/core/compiler/binding_propagation_config';
1213

1314
export * from './src/core/dom/element';

modules/angular2/src/change_detection/abstract_change_detector.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@ export class AbstractChangeDetector extends ChangeDetector {
5151
children[i]._detectChanges(throwOnChange);
5252
}
5353
}
54+
55+
markPathToRootAsCheckOnce() {
56+
var c = this;
57+
while(isPresent(c) && c.mode != DETACHED) {
58+
if (c.mode === CHECKED) c.mode = CHECK_ONCE;
59+
c = c.parent;
60+
}
61+
}
5462
}

modules/angular2/src/change_detection/change_detection_util.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,4 @@ export class ChangeDetectionUtil {
214214
}
215215
return updatedRecords;
216216
}
217-
218-
static markPathToRootAsCheckOnce(cd:ChangeDetector) {
219-
var c = cd;
220-
while(isPresent(c) && c.mode != DETACHED) {
221-
if (c.mode === CHECKED) c.mode = CHECK_ONCE;
222-
c = c.parent;
223-
}
224-
}
225217
}

modules/angular2/test/change_detection/change_detection_spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ export function main() {
535535
var checkOnceChild = changeDetector(CHECK_ONCE, checkAlwaysChild);
536536
var checkedChild = changeDetector(CHECKED, checkOnceChild);
537537

538-
ChangeDetectionUtil.markPathToRootAsCheckOnce(checkedChild);
538+
checkedChild.markPathToRootAsCheckOnce();
539539

540540
expect(root.mode).toEqual(CHECK_ALWAYS);
541541
expect(disabled.mode).toEqual(DETACHED);

modules/angular2/test/core/compiler/integration_spec.js

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {Compiler, CompilerCache} from 'angular2/src/core/compiler/compiler';
99
import {DirectiveMetadataReader} from 'angular2/src/core/compiler/directive_metadata_reader';
1010
import {NativeShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
1111
import {TemplateLoader} from 'angular2/src/core/compiler/template_loader';
12+
import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propagation_config';
1213

1314
import {Decorator, Component, Template} from 'angular2/src/core/annotations/annotations';
1415
import {TemplateConfig} from 'angular2/src/core/annotations/template_config';
@@ -198,6 +199,26 @@ export function main() {
198199
done();
199200
})
200201
});
202+
203+
it('should provide binding configuration config to the component', (done) => {
204+
compiler.compile(MyComp, el('<push-cmp #cmp></push-cmp>')).then((pv) => {
205+
createView(pv);
206+
207+
var cmp = view.contextWithLocals.get('cmp');
208+
209+
cd.detectChanges();
210+
expect(cmp.numberOfChecks).toEqual(1);
211+
212+
cd.detectChanges();
213+
expect(cmp.numberOfChecks).toEqual(1);
214+
215+
cmp.propagate();
216+
217+
cd.detectChanges();
218+
expect(cmp.numberOfChecks).toEqual(2);
219+
done();
220+
})
221+
});
201222
});
202223
});
203224
}
@@ -213,9 +234,35 @@ class MyDir {
213234
}
214235
}
215236

237+
@Component({
238+
selector: 'push-cmp',
239+
template: new TemplateConfig({
240+
inline: '{{field}}'
241+
})
242+
})
243+
class PushBasedComp {
244+
numberOfChecks:number;
245+
bpc:BindingPropagationConfig;
246+
247+
constructor(bpc:BindingPropagationConfig) {
248+
this.numberOfChecks = 0;
249+
this.bpc = bpc;
250+
bpc.shouldBePropagated();
251+
}
252+
253+
get field(){
254+
this.numberOfChecks++;
255+
return "fixed";
256+
}
257+
258+
propagate() {
259+
this.bpc.shouldBePropagatedFromRoot();
260+
}
261+
}
262+
216263
@Component({
217264
template: new TemplateConfig({
218-
directives: [MyDir, ChildComp, SomeTemplate]
265+
directives: [MyDir, ChildComp, SomeTemplate, PushBasedComp]
219266
})
220267
})
221268
class MyComp {

0 commit comments

Comments
 (0)