From 86ec386674480b3fa9fa9fce288b99e7e18a27e7 Mon Sep 17 00:00:00 2001 From: Kostas Karachalios Date: Fri, 7 Feb 2014 13:13:42 +0100 Subject: [PATCH 1/5] Rename hasNext to hasNextPage and hasPrevious to hasPreviousPage --- README.rst | 2 +- .../js/extensions/paginator/backgrid-paginator.js | 4 ++-- lib/backbone-pageable.js | 4 ++-- test/client-pageable.js | 14 +++++++------- test/infinite-pageable.js | 14 +++++++------- 5 files changed, 19 insertions(+), 19 deletions(-) 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/examples/js/extensions/paginator/backgrid-paginator.js b/examples/js/extensions/paginator/backgrid-paginator.js index a0b3af9..9a032e5 100644 --- a/examples/js/extensions/paginator/backgrid-paginator.js +++ b/examples/js/extensions/paginator/backgrid-paginator.js @@ -166,8 +166,8 @@ var pageIndex = this.pageIndex; if (this.isRewind && currentPage == state.firstPage || - this.isBack && !collection.hasPrevious() || - this.isForward && !collection.hasNext() || + this.isBack && !collection.hasPreviousPage() || + this.isForward && !collection.hasNextPage() || this.isFastForward && (currentPage == state.lastPage || state.totalPages < 1)) { this.$el.addClass("disabled"); } diff --git a/lib/backbone-pageable.js b/lib/backbone-pageable.js index 9094262..828ec4e 100644 --- a/lib/backbone-pageable.js +++ b/lib/backbone-pageable.js @@ -745,7 +745,7 @@ @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; @@ -756,7 +756,7 @@ @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; diff --git a/test/client-pageable.js b/test/client-pageable.js index c403f8b..45fd870 100644 --- a/test/client-pageable.js +++ b/test/client-pageable.js @@ -922,7 +922,7 @@ $(document).ready(function () { strictEqual(col.state.totalPages, 1); }); - test("hasNext and hasPrevious", function () { + test("hasNextPage and hasPreviousPage", function () { var col = new Backbone.PageableCollection(models, { state: { pageSize: 1 @@ -930,18 +930,18 @@ $(document).ready(function () { mode: "client" }); - strictEqual(col.hasPrevious(), false); - strictEqual(col.hasNext(), true); + strictEqual(col.hasPreviousPage(), false); + strictEqual(col.hasNextPage(), true); col.getNextPage(); - strictEqual(col.hasPrevious(), true); - strictEqual(col.hasNext(), true); + strictEqual(col.hasPreviousPage(), true); + strictEqual(col.hasNextPage(), true); col.getLastPage(); - strictEqual(col.hasPrevious(), true); - strictEqual(col.hasNext(), false); + strictEqual(col.hasPreviousPage(), true); + strictEqual(col.hasNextPage(), false); }); test("parsing from constructor #112", function () { diff --git a/test/infinite-pageable.js b/test/infinite-pageable.js index f3068a4..e8700a5 100644 --- a/test/infinite-pageable.js +++ b/test/infinite-pageable.js @@ -252,7 +252,7 @@ $(document).ready(function () { col.parseLinks.restore(); }); - test("hasNext and hasPrevious", function () { + test("hasNextPage and hasPreviousPage", function () { var col = new (Backbone.PageableCollection.extend({ url: "url" }))([ @@ -266,18 +266,18 @@ $(document).ready(function () { mode: "infinite" }); - strictEqual(col.hasPrevious(), false); - strictEqual(col.hasNext(), true); + strictEqual(col.hasPreviousPage(), false); + strictEqual(col.hasNextPage(), true); col.getNextPage(); - strictEqual(col.hasPrevious(), true); - strictEqual(col.hasNext(), true); + strictEqual(col.hasPreviousPage(), true); + strictEqual(col.hasNextPage(), true); col.getLastPage(); - strictEqual(col.hasPrevious(), true); - strictEqual(col.hasNext(), false); + strictEqual(col.hasPreviousPage(), true); + strictEqual(col.hasNextPage(), false); }); }); From 4b8612b700d0cb7e28b5dc3cd9457ae0ab0b2e19 Mon Sep 17 00:00:00 2001 From: Kostas Karachalios Date: Sun, 23 Feb 2014 23:17:54 +0100 Subject: [PATCH 2/5] Delegate old hasNext & hasPrevious to hasNextPage & hasPreviousPage --- lib/backbone-pageable.js | 20 ++++++++++++++++++++ test/client-pageable.js | 23 +++++++++++++++++++++++ test/infinite-pageable.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) diff --git a/lib/backbone-pageable.js b/lib/backbone-pageable.js index 828ec4e..a253b66 100644 --- a/lib/backbone-pageable.js +++ b/lib/backbone-pageable.js @@ -752,6 +752,16 @@ return !!this.links[currentPage - 1]; }, + /** + Delegates to hasPreviousPage. + */ + hasPrevious: function () { + var msg = "hasPrevious has been deprecated, use hasPreviousPage instead"; + console && console.warn && console.warn(msg); + + return this.hasPreviousPage(); + }, + /** @return {boolean} `true` if this collection can page forward, `false` otherwise. @@ -763,6 +773,16 @@ return !!this.links[currentPage + 1]; }, + /** + Delegates to hasNextPage. + */ + hasNext: function () { + var msg = "hasNext has been deprecated, use hasNextPage instead"; + console && 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 45fd870..4afeefd 100644 --- a/test/client-pageable.js +++ b/test/client-pageable.js @@ -944,6 +944,29 @@ $(document).ready(function () { strictEqual(col.hasNextPage(), false); }); + // Just a duplicate of the above + test("deprecated hasNext and hasPrevious", function () { + var col = new Backbone.PageableCollection(models, { + state: { + pageSize: 1 + }, + mode: "client" + }); + + strictEqual(col.hasPrevious(), false); + strictEqual(col.hasNext(), true); + + col.getNextPage(); + + strictEqual(col.hasPrevious(), true); + strictEqual(col.hasNext(), true); + + col.getLastPage(); + + strictEqual(col.hasPrevious(), true); + strictEqual(col.hasNext(), false); + }); + test("parsing from constructor #112", function () { var Model = Backbone.Model.extend({ parse: function (raw) { diff --git a/test/infinite-pageable.js b/test/infinite-pageable.js index e8700a5..f51d8c7 100644 --- a/test/infinite-pageable.js +++ b/test/infinite-pageable.js @@ -280,4 +280,33 @@ $(document).ready(function () { strictEqual(col.hasNextPage(), false); }); + // Just a duplicate of the above + test("deprecated hasNext and hasPrevious", function () { + var col = new (Backbone.PageableCollection.extend({ + url: "url" + }))([ + {id: 1}, + {id: 2}, + {id: 3} + ], { + state: { + pageSize: 1 + }, + mode: "infinite" + }); + + strictEqual(col.hasPrevious(), false); + strictEqual(col.hasNext(), true); + + col.getNextPage(); + + strictEqual(col.hasPrevious(), true); + strictEqual(col.hasNext(), true); + + col.getLastPage(); + + strictEqual(col.hasPrevious(), true); + strictEqual(col.hasNext(), false); + }); + }); From d26590f1ce20ca27b439d25ab7905b9b4340b86d Mon Sep 17 00:00:00 2001 From: Kostas Karachalios Date: Mon, 24 Feb 2014 10:27:57 +0100 Subject: [PATCH 3/5] Prevent throwing a ReferenceError --- lib/backbone-pageable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/backbone-pageable.js b/lib/backbone-pageable.js index a253b66..c29187f 100644 --- a/lib/backbone-pageable.js +++ b/lib/backbone-pageable.js @@ -757,7 +757,7 @@ */ hasPrevious: function () { var msg = "hasPrevious has been deprecated, use hasPreviousPage instead"; - console && console.warn && console.warn(msg); + typeof console != 'undefined' && console.warn && console.warn(msg); return this.hasPreviousPage(); }, @@ -778,7 +778,7 @@ */ hasNext: function () { var msg = "hasNext has been deprecated, use hasNextPage instead"; - console && console.warn && console.warn(msg); + typeof console != 'undefined' && console.warn && console.warn(msg); return this.hasNextPage(); }, From 6e4687fa35c86fa34f15f67279222abad84c44a2 Mon Sep 17 00:00:00 2001 From: Kostas Karachalios Date: Mon, 24 Feb 2014 10:44:41 +0100 Subject: [PATCH 4/5] Remove duplicate tests --- test/client-pageable.js | 26 ++------------------------ test/infinite-pageable.js | 32 ++------------------------------ 2 files changed, 4 insertions(+), 54 deletions(-) diff --git a/test/client-pageable.js b/test/client-pageable.js index 4afeefd..a9f9c0d 100644 --- a/test/client-pageable.js +++ b/test/client-pageable.js @@ -922,30 +922,8 @@ $(document).ready(function () { strictEqual(col.state.totalPages, 1); }); - test("hasNextPage and hasPreviousPage", function () { - var col = new Backbone.PageableCollection(models, { - state: { - pageSize: 1 - }, - mode: "client" - }); - - strictEqual(col.hasPreviousPage(), false); - strictEqual(col.hasNextPage(), true); - - col.getNextPage(); - - strictEqual(col.hasPreviousPage(), true); - strictEqual(col.hasNextPage(), true); - - col.getLastPage(); - - strictEqual(col.hasPreviousPage(), true); - strictEqual(col.hasNextPage(), false); - }); - - // Just a duplicate of the above - test("deprecated hasNext and hasPrevious", function () { + // emits some deprecation warnings + test("hasNext and hasPrevious", function () { var col = new Backbone.PageableCollection(models, { state: { pageSize: 1 diff --git a/test/infinite-pageable.js b/test/infinite-pageable.js index f51d8c7..b992540 100644 --- a/test/infinite-pageable.js +++ b/test/infinite-pageable.js @@ -252,36 +252,8 @@ $(document).ready(function () { col.parseLinks.restore(); }); - test("hasNextPage and hasPreviousPage", function () { - var col = new (Backbone.PageableCollection.extend({ - url: "url" - }))([ - {id: 1}, - {id: 2}, - {id: 3} - ], { - state: { - pageSize: 1 - }, - mode: "infinite" - }); - - strictEqual(col.hasPreviousPage(), false); - strictEqual(col.hasNextPage(), true); - - col.getNextPage(); - - strictEqual(col.hasPreviousPage(), true); - strictEqual(col.hasNextPage(), true); - - col.getLastPage(); - - strictEqual(col.hasPreviousPage(), true); - strictEqual(col.hasNextPage(), false); - }); - - // Just a duplicate of the above - test("deprecated hasNext and hasPrevious", function () { + // emits some deprecation warnings + test("hasNext and hasPrevious", function () { var col = new (Backbone.PageableCollection.extend({ url: "url" }))([ From 0c091d2278f03564ca5d1d8cbd092f97e700b76b Mon Sep 17 00:00:00 2001 From: Kostas Karachalios Date: Mon, 24 Feb 2014 15:29:30 +0100 Subject: [PATCH 5/5] Revert examples --- examples/js/extensions/paginator/backgrid-paginator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/js/extensions/paginator/backgrid-paginator.js b/examples/js/extensions/paginator/backgrid-paginator.js index 9a032e5..a0b3af9 100644 --- a/examples/js/extensions/paginator/backgrid-paginator.js +++ b/examples/js/extensions/paginator/backgrid-paginator.js @@ -166,8 +166,8 @@ var pageIndex = this.pageIndex; if (this.isRewind && currentPage == state.firstPage || - this.isBack && !collection.hasPreviousPage() || - this.isForward && !collection.hasNextPage() || + this.isBack && !collection.hasPrevious() || + this.isForward && !collection.hasNext() || this.isFastForward && (currentPage == state.lastPage || state.totalPages < 1)) { this.$el.addClass("disabled"); }