Skip to content

Instantly share code, notes, and snippets.

@kborchers
Last active December 11, 2015 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kborchers/4539188 to your computer and use it in GitHub Desktop.
Save kborchers/4539188 to your computer and use it in GitHub Desktop.

Pipe uses default offset and limit so no need to define those, just tell it that it's paged via headers.

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.

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

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:

pagedPipe.updatePageConfig({
    paged: false
});

Now next() or read() return all items from the endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment