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

Commit

Permalink
Fix #56 Giving some love to Backbone 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wyuenho committed Mar 20, 2013
1 parent 8652431 commit 3dbf44a
Show file tree
Hide file tree
Showing 9 changed files with 3,979 additions and 1,065 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ doc:
test: FORCE
phantomjs test/runner.js test/index.html?noglobals=true
phantomjs test/runner.js test/test-zepto.html?noglobals=true
phantomjs test/runner.js test/index.0.9.10.html?noglobals=true
phantomjs test/runner.js test/index.0.9.9.html?noglobals=true
18 changes: 9 additions & 9 deletions lib/backbone-pageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
var _keys = _.keys;
var _isUndefined = _.isUndefined;
var _result = _.result;
var _bind = _.bind;
var ceil = Math.ceil;
var max = Math.max;

Expand Down Expand Up @@ -374,8 +373,9 @@

/**
Factory method that returns a Backbone event handler that responses to
the `all` event. The returned event handler will synchronize the current
page collection and the full collection's models.
the `add`, `remove`, `reset`, and the `sort` events. The returned event
handler will synchronize the current page collection and the full
collection's models.
@private
Expand All @@ -388,7 +388,6 @@
_makeCollectionEventHandler: function (pageCol, fullCol) {

return function collectionEventHandler (event, model, collection, options) {

var handlers = pageCol._handlers;
_each(_keys(handlers), function (event) {
var handler = handlers[event];
Expand Down Expand Up @@ -433,7 +432,7 @@
pageCol.at(pageSize) :
null;
if (modelToRemove) {
var addHandlers = collection._events.add,
var addHandlers = collection._events.add || [],
popOptions = {onAdd: true};
if (addHandlers.length) {
var lastAddHandler = addHandlers[addHandlers.length - 1];
Expand Down Expand Up @@ -511,7 +510,7 @@
var handler = handlers[event];
_each([pageCol, fullCol], function (col) {
col.on(event, handler);
var callbacks = col._events[event];
var callbacks = col._events[event] || [];
callbacks.unshift(callbacks.pop());
});
});
Expand Down Expand Up @@ -673,7 +672,7 @@
this.fullCollection = fullCollection;
var allHandler = this._makeCollectionEventHandler(this, fullCollection);
_each(["add", "remove", "reset", "sort"], function (event) {
handlers[event] = handler = _bind(allHandler, {}, event);
handlers[event] = handler = _.bind(allHandler, {}, event);
self.on(event, handler);
fullCollection.on(event, handler);
});
Expand Down Expand Up @@ -1158,8 +1157,9 @@
var head = fullModels.slice(0, pageStart);
var tail = fullModels.slice(pageStart + pageSize);
fullModels = head.concat(models).concat(tail);
fullCollection.update(fullModels,
_extend({silent: true, sort: false}, opts));
var updateFunc = fullCollection.set || fullCollection.update;
updateFunc.call(fullCollection, fullModels,
_extend({silent: true, sort: false}, opts));
if (fullCollection.comparator) fullCollection.sort();
fullCollection.trigger("reset", fullCollection, opts);
}
Expand Down
Loading

0 comments on commit 3dbf44a

Please sign in to comment.