Skip to content
This repository was archived by the owner on May 17, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Method Use When
``switchMode`` Switching between modes
``state`` Need to read the internal state
``get*Page`` Need to go to a different page
``hasPrevious, hasNext`` Check if paging backward or forward is possible
``hasPreviousPage, hasNextPage`` Check if paging backward or forward is possible
======================== ===============================================

In addition to the above methods, you can also synchronize the state with the
Expand Down
24 changes: 22 additions & 2 deletions lib/backbone-pageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,24 +745,44 @@
@return {boolean} `true` if this collection can page backward, `false`
otherwise.
*/
hasPrevious: function () {
hasPreviousPage: function () {
var state = this.state;
var currentPage = state.currentPage;
if (this.mode != "infinite") return currentPage > state.firstPage;
return !!this.links[currentPage - 1];
},

/**
Delegates to hasPreviousPage.
*/
hasPrevious: function () {
var msg = "hasPrevious has been deprecated, use hasPreviousPage instead";
typeof console != 'undefined' && console.warn && console.warn(msg);

return this.hasPreviousPage();
},

/**
@return {boolean} `true` if this collection can page forward, `false`
otherwise.
*/
hasNext: function () {
hasNextPage: function () {
var state = this.state;
var currentPage = this.state.currentPage;
if (this.mode != "infinite") return currentPage < state.lastPage;
return !!this.links[currentPage + 1];
},

/**
Delegates to hasNextPage.
*/
hasNext: function () {
var msg = "hasNext has been deprecated, use hasNextPage instead";
typeof console != 'undefined' && console.warn && console.warn(msg);

return this.hasNextPage();
},

/**
Fetch the first page in server mode, or reset the current page of this
collection to the first page in client or infinite mode.
Expand Down
1 change: 1 addition & 0 deletions test/client-pageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ $(document).ready(function () {
strictEqual(col.state.totalPages, 1);
});

// emits some deprecation warnings
test("hasNext and hasPrevious", function () {
var col = new Backbone.PageableCollection(models, {
state: {
Expand Down
1 change: 1 addition & 0 deletions test/infinite-pageable.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ $(document).ready(function () {
col.parseLinks.restore();
});

// emits some deprecation warnings
test("hasNext and hasPrevious", function () {
var col = new (Backbone.PageableCollection.extend({
url: "url"
Expand Down