Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions modules/angular2/src/change_detection/dynamic_change_detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
var bindingRecord = proto.bindingRecord;
var directiveRecord = bindingRecord.directiveRecord;

var change = this._check(proto);
var change = this._check(proto, throwOnChange);
if (isPresent(change)) {
if (throwOnChange) ChangeDetectionUtil.throwOnChange(proto, change);
this._updateDirectiveOrElement(change, bindingRecord);
isChanged = true;
changes = this._addChange(bindingRecord, change, changes);
Expand Down Expand Up @@ -144,19 +143,19 @@ export class DynamicChangeDetector extends AbstractChangeDetector {

_getDetectorFor(directiveIndex) { return this.directives.getDetectorFor(directiveIndex); }

_check(proto: ProtoRecord): SimpleChange {
_check(proto: ProtoRecord, throwOnChange: boolean): SimpleChange {
try {
if (proto.mode === RECORD_TYPE_PIPE || proto.mode === RECORD_TYPE_BINDING_PIPE) {
return this._pipeCheck(proto);
return this._pipeCheck(proto, throwOnChange);
} else {
return this._referenceCheck(proto);
return this._referenceCheck(proto, throwOnChange);
}
} catch (e) {
throw new ChangeDetectionError(proto, e);
}
}

_referenceCheck(proto: ProtoRecord) {
_referenceCheck(proto: ProtoRecord, throwOnChange: boolean) {
if (this._pureFuncAndArgsDidNotChange(proto)) {
this._setChanged(proto, false);
return null;
Expand All @@ -166,12 +165,18 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
var currValue = this._calculateCurrValue(proto);

if (!isSame(prevValue, currValue)) {
this._writeSelf(proto, currValue);
this._setChanged(proto, true);

if (proto.lastInBinding) {
return ChangeDetectionUtil.simpleChange(prevValue, currValue);
var change = ChangeDetectionUtil.simpleChange(prevValue, currValue);
if (throwOnChange) ChangeDetectionUtil.throwOnChange(proto, change);

this._writeSelf(proto, currValue);
this._setChanged(proto, true);

return change;

} else {
this._writeSelf(proto, currValue);
this._setChanged(proto, true);
return null;
}
} else {
Expand Down Expand Up @@ -216,22 +221,28 @@ export class DynamicChangeDetector extends AbstractChangeDetector {
}
}

_pipeCheck(proto: ProtoRecord) {
_pipeCheck(proto: ProtoRecord, throwOnChange: boolean) {
var context = this._readContext(proto);
var pipe = this._pipeFor(proto, context);
var prevValue = this._readSelf(proto);

var newValue = pipe.transform(context);
var currValue = pipe.transform(context);

if (!isSame(prevValue, newValue)) {
newValue = ChangeDetectionUtil.unwrapValue(newValue);

this._writeSelf(proto, newValue);
this._setChanged(proto, true);
if (!isSame(prevValue, currValue)) {
currValue = ChangeDetectionUtil.unwrapValue(currValue);

if (proto.lastInBinding) {
return ChangeDetectionUtil.simpleChange(prevValue, newValue);
var change = ChangeDetectionUtil.simpleChange(prevValue, currValue);
if (throwOnChange) ChangeDetectionUtil.throwOnChange(proto, change);

this._writeSelf(proto, currValue);
this._setChanged(proto, true);

return change;

} else {
this._writeSelf(proto, currValue);
this._setChanged(proto, true);
return null;
}
} else {
Expand Down
16 changes: 16 additions & 0 deletions modules/angular2/test/change_detection/change_detection_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,22 @@ export function main() {
cd.checkNoChanges();
}).toThrowError(new RegExp("Expression 'a in location' has changed after it was checked"));
});

it("should not break the next run", () => {
var pcd = createProtoChangeDetector([
BindingRecord.createForElement(ast("a"), 0, "a")
]);

var dispatcher = new TestDispatcher();
var cd = pcd.instantiate(dispatcher);
cd.hydrate(new TestData('value'), null, null);

expect(() => cd.checkNoChanges()).toThrow();

cd.detectChanges();

expect(dispatcher.loggedValues).toEqual(['value']);
});
});

//TODO vsavkin: implement it
Expand Down