Forked from kborchers/paging-usage-comparison.md
Last active
December 11, 2015 03:59
Revisions
-
secondsun revised this gist
Jan 15, 2013 . 1 changed file with 2 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,28 +5,21 @@ Below is a comparison of the method usage proposed by each lib for handling page ### Android ```Java ReadFilter filter = new ReadFilter(); filter.setLimit(5); cars.readWithFilter(filter, new Callback<Car>() { @Override void onSuccess(List<Car> data) { firstPage = data; } @Override void onError(Exception ex) { //handle error } }); firstPage.next(new CallBack<Car>() { @Override @@ -67,29 +60,21 @@ cars.read({ ### Android ```Java ReadFilter filter = new ReadFilter(); filter.setLimit(5); filter.setOffset(1); cars.readWithFilter(filter, new Callback<Car>() { @Override void onSuccess(List<Car> data) { secondPage = data; } @Override void onError(Exception ex) { //handle error } }); secondPage.prev(new CallBack<Car>() { @Override void onSuccess(List<Car> firstPagedList) { -
secondsun revised this gist
Jan 15, 2013 . 1 changed file with 47 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -101,8 +101,6 @@ secondPage.prev(new CallBack<Car>() { //handle error } }); ``` ### iOS @@ -128,7 +126,42 @@ cars.read({ ###Android ```Java ReadFilter filter = new ReadFilter(); filter.setLimit(5); filter.setOffset(1); cars.readWithFilter(filter, new Callback<Car>() { @Override void onSuccess(List<Car> data) { //do something } @Override void onError(Exception ex) { //handle error } }); filter = new ReadFilter(); filter.setLimit(50); filter.setOffset(0); cars.readWithFilter(filter, new Callback<Car>() { @Override void onSuccess(List<Car> data) { //do something } @Override void onError(Exception ex) { //handle error } }); ``` ###iOS @@ -150,6 +183,18 @@ cars.updatePageConfig({ ### Android ```Java cars.read(new Callback<Car>() { @Override void onSuccess(List<Car> allRecords) { //do something } @Override void onError(Exception ex) { //handle error } }); ``` ### iOS -
secondsun revised this gist
Jan 15, 2013 . 1 changed file with 36 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -67,6 +67,42 @@ cars.read({ ### Android ```Java final AtomicReference<PagedList<Car>> secondPageReference = new AtomicReference<PagedList<Car>>(); final CountdownLatch latch = new CountdownLatch(1); ReadFilter filter = new ReadFilter(); filter.setLimit(5); filter.setOffset(1); cars.readWithFilter(filter, new Callback<Car>() { @Override void onSuccess(List<Car> data) { secondPageReference.set( (PagedList) data); latch.countDown(); } @Override void onError(Exception ex) { //handle error latch.countDown(); } }); latch.await(); PagedList<Car> secondPage = secondPageReference.get(); secondPage.prev(new CallBack<Car>() { @Override void onSuccess(List<Car> firstPagedList) { //Do somethign with second Paged list } @Override void onError(Exception ex) { //handle error } }); ``` ### iOS -
secondsun revised this gist
Jan 15, 2013 . 1 changed file with 30 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,19 +5,42 @@ Below is a comparison of the method usage proposed by each lib for handling page ### Android ```Java final AtomicReference<PagedList<Car>> firstPageReference = new AtomicReference<PagedList<Car>>(); final CountdownLatch latch = new CountdownLatch(1); ReadFilter filter = new ReadFilter(); filter.setLimit(5); cars.readWithFilter(filter, new Callback<Car>() { @Override void onSuccess(List<Car> data) { firstPageReference.set( (PagedList) data); latch.countDown(); } @Override void onError(Exception ex) { //handle error latch.countDown(); } }); latch.await(); PagedList<Car> firstPage = firstPageReference.get(); firstPage.next(new CallBack<Car>() { @Override void onSuccess(List<Car> secondPagedList) { //Do somethign with second Paged list } @Override void onError(Exception ex) { //handle error } }); ``` ### iOS -
secondsun revised this gist
Jan 15, 2013 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,19 @@ Below is a comparison of the method usage proposed by each lib for handling page ### Android ```Java //blocking PagedList secondPage = firstPage.next(); //Async firstPage.next(new CallBack() { void onSuccess(List secondList) { //doSomething } void onError(Exception ex) { //handle Error } }); ``` ### iOS -
kborchers revised this gist
Jan 15, 2013 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -88,6 +88,18 @@ cars.updatePageConfig({ ### JS ```JS // Get all records for a single read but continue paging aftwerward cars.read({ page: false, success: function( data ) { // do something }, error: function() { // handle it } }); // Or permanently update the config to no longer page the results cars.updatePageConfig({ paged: false }); -
kborchers revised this gist
Jan 15, 2013 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,9 @@ Below is a comparison of the method usage proposed by each lib for handling page ### iOS ```ObjC ``` ### JS ```JS @@ -32,6 +35,9 @@ cars.read({ ### iOS ```ObjC ``` ### JS ```JS @@ -55,6 +61,9 @@ cars.read({ ###iOS ```ObjC ``` ###JS ```JS @@ -73,6 +82,9 @@ cars.updatePageConfig({ ### iOS ```ObjC ``` ### JS ```JS -
kborchers revised this gist
Jan 15, 2013 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,9 @@ Below is a comparison of the method usage proposed by each lib for handling page ### Android ```Java ``` ### iOS ### JS @@ -24,6 +27,9 @@ cars.read({ ### Android ```Java ``` ### iOS ### JS @@ -44,6 +50,9 @@ cars.read({ ###Android ```Java ``` ###iOS ###JS @@ -59,6 +68,9 @@ cars.updatePageConfig({ ### Android ```Java ``` ### iOS ### JS -
kborchers revised this gist
Jan 15, 2013 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -57,6 +57,12 @@ cars.updatePageConfig({ ## Return All Records (No longer paged) ### Android ### iOS ### JS ```JS cars.updatePageConfig({ paged: false -
kborchers revised this gist
Jan 15, 2013 . 1 changed file with 39 additions and 28 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,38 +1,36 @@ Below is a comparison of the method usage proposed by each lib for handling paged resources. ## Read Next Page ### Android ### iOS ### JS ```JS cars.read({ page: "next", success: function( data ) { // do something }, error: function() { // handle it } }); ``` ## Read Previous Page ### Android ### iOS ### JS ```JS cars.read({ page: "prev", success: function( data ) { // do something }, @@ -42,21 +40,34 @@ pagedPipe.prev({ }); ``` ## Change Offset and Limit ###Android ###iOS ###JS ```JS cars.updatePageConfig({ offset: 2, limit: 10 }); ``` ## Return All Records (No longer paged) ```JS cars.updatePageConfig({ paged: false }); cars.read({ success: function( data ) { // do something }, error: function() { // handle it } }); ``` -
kborchers created this gist
Jan 15, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ Pipe uses default offset and limit so no need to define those, just tell it that it's paged via headers. ```JS var pagedPipe = AeroGear.Pipeline({ name: "cars", settings: { paged: "headers" } }).pipes.cars; ``` We could either do a read() or next() as next() would determine that there isn't a current page and get the first page. ```JS pagedPipe.next({ success: function( data ) { // do something }, error: function() { // handle it } }); // Get the second page pagedPipe.next({ success: function( data ) { // do something }, error: function() { // handle it } }); // Back to first page pagedPipe.prev({ success: function( data ) { // do something }, error: function() { // handle it } }); ``` Now we want 10 per page and to start on page 3 ```JS pagedPipe.updatePageConfig({ offset: 2, limit: 10 }); ``` Now next() will get the second 10 items. Then we could go as far to even say we don't want it paged anymore: ```JS pagedPipe.updatePageConfig({ paged: false }); ``` Now next() or read() return all items from the endpoint.