Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Include observed array as forth callback arg for non-valueFn Compound…
Browse files Browse the repository at this point in the history
…PathObserver.

The array is a set of tuples: [object, path, object, path, ....];

R=arv
BUG=

Review URL: https://codereview.appspot.com/14251043
  • Loading branch information
rafaelw committed Oct 2, 2013
1 parent c97eec7 commit 16f8b7c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,8 @@

this.reportArgs = [this.value, this.oldValue];
} else {
this.reportArgs = [this.values, this.oldValues, this.changeFlags];
this.reportArgs = [this.values, this.oldValues, this.changeFlags,
this.observed];
}

return true;
Expand Down
16 changes: 12 additions & 4 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,19 @@ function assertPathChanges(expectNewValue, expectOldValue) {
}

function assertCompoundPathChanges(expectNewValues, expectOldValues,
expectChangeFlags) {
expectChangeFlags, expectObserverArg) {
observer.deliver();

assert.isTrue(callbackInvoked);

var newValues = callbackArgs[0];
var oldValues = callbackArgs[1];
var changeFlags = callbackArgs[2];
var observerArg = callbackArgs[3];
assert.deepEqual(expectNewValues, newValues);
assert.deepEqual(expectOldValues, oldValues);
assert.deepEqual(expectChangeFlags, changeFlags);
assert.deepEqual(expectObserverArg, observerArg);

assert.isTrue(window.dirtyCheckCycleCount === undefined ||
window.dirtyCheckCycleCount === 1);
Expand Down Expand Up @@ -850,19 +852,25 @@ suite('CompoundPathObserver Tests', function() {
observer.addPath(model, Path.get('c'));
observer.start();

var observerCallbackArg = [model, Path.get('a'),
model, Path.get('b'),
model, Path.get('c')];
model.a = -10;
model.b = 20;
model.c = 30;
assertCompoundPathChanges([-10, 20, 30], [1, 2, 3], [true, true, true]);
assertCompoundPathChanges([-10, 20, 30], [1, 2, 3],
[true, true, true],
observerCallbackArg);

model.a = 'a';
model.c = 'c';
assertCompoundPathChanges(['a', 20, 'c'], [-10, 20, 30], [true, false, true]);
assertCompoundPathChanges(['a', 20, 'c'], [-10, 20, 30],
[true, false, true],
observerCallbackArg);

observer.close();
});


test('Simple - valueFn', function() {
var model = { a: 1, b: 2, c: 3 };

Expand Down

0 comments on commit 16f8b7c

Please sign in to comment.