diff --git a/README.rst b/README.rst index 4214cf7..a0810e9 100644 --- a/README.rst +++ b/README.rst @@ -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 diff --git a/lib/backbone-pageable.js b/lib/backbone-pageable.js index 9094262..c29187f 100644 --- a/lib/backbone-pageable.js +++ b/lib/backbone-pageable.js @@ -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. diff --git a/test/client-pageable.js b/test/client-pageable.js index c403f8b..a9f9c0d 100644 --- a/test/client-pageable.js +++ b/test/client-pageable.js @@ -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: { diff --git a/test/infinite-pageable.js b/test/infinite-pageable.js index f3068a4..b992540 100644 --- a/test/infinite-pageable.js +++ b/test/infinite-pageable.js @@ -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"