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

Commit

Permalink
Fix #34 fetching in infinite mode no longer triggers add and remove e…
Browse files Browse the repository at this point in the history
…vents on update
  • Loading branch information
wyuenho committed Feb 3, 2013
1 parent 6e00b1d commit 2aa79c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/backbone-pageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
var _isArray = _.isArray;
var _isFunction = _.isFunction;
var _keys = _.keys;
var _isUndefined = _.isUndefined;
var ceil = Math.ceil;

var BBColProto = Backbone.Collection.prototype;
Expand Down Expand Up @@ -353,7 +354,7 @@
var proto = {};
for (i = 0, length = properties.length; i < length; i++) {
prop = properties[i];
if (!_.isUndefined(thisProto[prop])) {
if (!_isUndefined(thisProto[prop])) {
proto[prop] = thisProto[prop];
}
}
Expand Down Expand Up @@ -1075,7 +1076,8 @@

// make sure the caller's intent is obeyed
opts = opts || {};
opts.silent = options.silent;
if (_isUndefined(options.silent)) delete opts.silent;
else opts.silent = options.silent;

var models = col.models;
var currentPage = state.currentPage;
Expand Down
34 changes: 29 additions & 5 deletions test/infinite-pageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,36 @@ $(document).ready(function () {
strictEqual(col.state.lastPage, 50);
});

test("fetch", 2, function () {
sinon.stub(Backbone.Collection.prototype, "fetch");
test("fetch", function () {
var ajax = $.ajax;
$.ajax = function (settings) {

strictEqual(settings.url, "url");
deepEqual(settings.data, {
page: 2,
"per_page": 2,
"total_entries": 4,
"total_pages": 2
});

settings.success([
{id: 5},
{id: 6}
]);
};

col.parseLinks = function () {
return {first: "url-1", next: "url-2"};
};

// makes sure normal add, remove and sort events are suppressed
col.on("all", function (event) {
if (_.contains(["add", "remove", "sort"], event)) ok(false);
});

col.fetch();
ok(Backbone.Collection.prototype.fetch.calledOnce);
strictEqual(Backbone.Collection.prototype.fetch.args[0][0].url, "url");
Backbone.Collection.prototype.fetch.restore();

$.ajax = ajax;
});

test("get*Page", 43, function () {
Expand Down

0 comments on commit 2aa79c3

Please sign in to comment.