Skip to content

Instantly share code, notes, and snippets.

@secondsun
Forked from kborchers/paging-usage-comparison.md
Last active December 11, 2015 03:59

Revisions

  1. secondsun revised this gist Jan 15, 2013. 1 changed file with 2 additions and 17 deletions.
    19 changes: 2 additions & 17 deletions paging-usage-comparison.md
    Original 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
    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();
    firstPage = data;
    }

    @Override
    void onError(Exception ex) {
    //handle error
    latch.countDown();
    }
    });

    latch.await();

    PagedList<Car> firstPage = firstPageReference.get();

    firstPage.next(new CallBack<Car>() {
    @Override
    @@ -67,29 +60,21 @@ 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();
    secondPage = data;
    }

    @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) {
  2. secondsun revised this gist Jan 15, 2013. 1 changed file with 47 additions and 2 deletions.
    49 changes: 47 additions & 2 deletions paging-usage-comparison.md
    Original 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
  3. secondsun revised this gist Jan 15, 2013. 1 changed file with 36 additions and 0 deletions.
    36 changes: 36 additions & 0 deletions paging-usage-comparison.md
    Original 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
  4. secondsun revised this gist Jan 15, 2013. 1 changed file with 30 additions and 7 deletions.
    37 changes: 30 additions & 7 deletions paging-usage-comparison.md
    Original 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
    //blocking
    PagedList secondPage = firstPage.next();
    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();
    }
    });

    //Async
    firstPage.next(new CallBack() {
    void onSuccess(List secondList) {
    //doSomething
    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
    //handle error
    }
    });


    ```

    ### iOS
  5. secondsun revised this gist Jan 15, 2013. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions paging-usage-comparison.md
    Original 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
  6. @kborchers kborchers revised this gist Jan 15, 2013. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions paging-usage-comparison.md
    Original 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
    });
  7. @kborchers kborchers revised this gist Jan 15, 2013. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions paging-usage-comparison.md
    Original 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
  8. @kborchers kborchers revised this gist Jan 15, 2013. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions paging-usage-comparison.md
    Original 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
  9. @kborchers kborchers revised this gist Jan 15, 2013. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions paging-usage-comparison.md
    Original 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
  10. @kborchers kborchers revised this gist Jan 15, 2013. 1 changed file with 39 additions and 28 deletions.
    67 changes: 39 additions & 28 deletions paging-usage-comparison.md
    Original file line number Diff line number Diff line change
    @@ -1,38 +1,36 @@
    Pipe uses default offset and limit so no need to define those, just tell it that it's paged via headers.
    Below is a comparison of the method usage proposed by each lib for handling paged resources.

    ```JS
    var pagedPipe = AeroGear.Pipeline({
    name: "cars",
    settings: {
    paged: "headers"
    }
    }).pipes.cars;
    ```
    ## Read Next Page

    ### Android

    We could either do a read() or next() as next() would determine that there isn't a current page and get the first page.
    ### iOS

    ### JS

    ```JS
    pagedPipe.next({
    cars.read({
    page: "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
    }
    });
    ## Read Previous Page

    ### Android

    ### iOS

    // Back to first page
    pagedPipe.prev({
    ### JS

    ```JS
    cars.read({
    page: "prev",
    success: function( data ) {
    // do something
    },
    @@ -42,21 +40,34 @@ pagedPipe.prev({
    });
    ```

    Now we want 10 per page and to start on page 3
    ## Change Offset and Limit

    ###Android

    ###iOS

    ###JS

    ```JS
    pagedPipe.updatePageConfig({
    cars.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:
    ## Return All Records (No longer paged)

    ```JS
    pagedPipe.updatePageConfig({
    cars.updatePageConfig({
    paged: false
    });
    ```

    Now next() or read() return all items from the endpoint.
    cars.read({
    success: function( data ) {
    // do something
    },
    error: function() {
    // handle it
    }
    });
    ```
  11. @kborchers kborchers created this gist Jan 15, 2013.
    62 changes: 62 additions & 0 deletions paging-usage-comparison.md
    Original 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.