Skip to content

Commit

Permalink
Fix array method return values.
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinRixham committed Dec 21, 2016
1 parent 148cb3e commit 657b94e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/array/method/Pop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define([], function() {

model.pop = function() {

originalPop.apply(this, arguments);
var popped = originalPop.apply(this, arguments);

var property = properties.pop();

Expand All @@ -21,6 +21,8 @@ define([], function() {
}

model.subscribableLength = model.length;

return popped;
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/array/method/Shift.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ define([], function() {

model.shift = function() {

originalShift.apply(this, arguments);
var shifted = originalShift.apply(this, arguments);

var property = properties.shift();

Expand All @@ -21,6 +21,8 @@ define([], function() {
}

model.subscribableLength = model.length;

return shifted;
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/array/method/Splice.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ define(["property/TransientProperty"], function(TransientProperty) {
removeObjects(start, deleteCount);
insertObjects(start, newObjects);

originalSplice.apply(this, arguments);
var spliced = originalSplice.apply(this, arguments);
model.subscribableLength = model.length;

return spliced;
};

function normaliseStart(start) {
Expand Down
6 changes: 4 additions & 2 deletions test/array/method/pop.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@
DOMElement,
TransientProperty) {

var model = [{}];
var object = {};
var model = [object];
var element = new DOMElement(document.querySelector("#pop"));
var elements = [element.toArrayElement(1)];
var propertyType = new FakePropertyType();
var properties = [new TransientProperty(model[0], propertyType)];

new Pop(model, elements, properties);

model.pop();
var popped = model.pop();

assert.strictEqual(model.length, 0);
assert.strictEqual(popped, object);
assert.strictEqual(properties.length, 0);
assert.strictEqual(element.get().children.length, 0);
assert.ok(propertyType.removeBindingWasCalled);
Expand Down
6 changes: 4 additions & 2 deletions test/array/method/shift.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@
DOMElement,
TransientProperty) {

var model = [{}];
var object = {};
var model = [object];
var element = new DOMElement(document.querySelector("#shift"));
var elements = [element.toArrayElement(1)];
var propertyType = new FakePropertyType();
var properties = [new TransientProperty(model[0], propertyType)];

new Shift(model, elements, properties);

model.shift();
var shifted = model.shift();

assert.strictEqual(model.length, 0);
assert.strictEqual(shifted, object);
assert.strictEqual(properties.length, 0);
assert.strictEqual(element.get().children.length, 0);
assert.ok(propertyType.removeBindingWasCalled);
Expand Down
7 changes: 5 additions & 2 deletions test/array/method/splice.html
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,19 @@
Splice,
DOMElement) {

var model = [{}];
var object = {};
var model = [object];
var element = new DOMElement(document.querySelector("#remove"));
var elements = [element.toArrayElement(1)];
var properties = [{}];

new Splice(model, elements, properties, new FakePropertyType());

model.splice(0, 1);
var spliced = model.splice(0, 1);

assert.strictEqual(model.length, 0);
assert.strictEqual(spliced.length, 1);
assert.strictEqual(spliced[0], object);
assert.strictEqual(element.get().children.length, 0);
assert.strictEqual(properties.length, 0);

Expand Down

0 comments on commit 657b94e

Please sign in to comment.