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

Commit

Permalink
Send splices to observe method when array property mutates.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Aug 13, 2014
1 parent e27162c commit df5db44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/instance/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
if (Array.isArray(value)) {
log.observe && console.log('[%s] observeArrayValue: register observer [%s]', this.localName, name, value);
var observer = new ArrayObserver(value);
observer.open(function(value, old) {
this.invokeMethod(callbackName, [old]);
observer.open(function(splices) {
this.invokeMethod(callbackName, [splices]);
}, this);
this.registerNamedObserver(name + '__array', observer);
}
Expand Down
15 changes: 9 additions & 6 deletions test/html/property-array-changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
this.a = a;
},
aChanged: function() {
this.nextTest();
this.nextTest(arguments);
},
bChanged: function() {
this.nextTest();
this.nextTest(arguments);
},
currentTest: 0,
getCurrentTest: function() {
return this['test' + this.currentTest];
},
nextTest: function() {
nextTest: function(args) {
var m = this.getCurrentTest();
//console.log(this.currentTest);
if (m) {
m.call(this);
m.apply(this, args);
}
this.currentTest++;
if (!this.getCurrentTest()) {
Expand All @@ -67,13 +67,16 @@
this.a.push(1);
this.a.push(2);
},
test4: function() {
test4: function(splices) {
chai.assert.equal(this.a, a1, 'array property is correct value');
chai.assert.equal(this.a.length, 2, 'noticed array addition');
chai.assert.equal(arguments.length, 1, 'only 1 argument when array mutates');
chai.assert.equal(splices[0].addedCount, 2, 'addedCount splice correctly sent in splices');
this.a.shift();
},
test5: function() {
test5: function(splices) {
chai.assert.equal(this.a.length, 1, 'noticed array removal');
chai.assert.equal(splices[0].removed.length, 1, 'removed splices correctly sent');
a.push(55);
setTimeout(this.nextTest.bind(this), 0);
},
Expand Down

0 comments on commit df5db44

Please sign in to comment.