From 8f88e0fb8330ce1aab10721b61cdf0fcd95352df Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 26 Aug 2015 11:53:37 -0600 Subject: [PATCH] Pass page options to next and prev --- api/mosaics.js | 2 +- api/page.js | 9 ++++----- api/quads.js | 2 +- api/scenes.js | 2 +- test/api/page.test.js | 12 ++++++------ 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/api/mosaics.js b/api/mosaics.js index cdc8e63..3d7965d 100644 --- a/api/mosaics.js +++ b/api/mosaics.js @@ -48,7 +48,7 @@ function search(query, options) { terminator: options.terminator }; return request.get(config).then(function(res) { - return new Page(res.body, search); + return new Page(res.body, search, options); }); } diff --git a/api/page.js b/api/page.js index 45ced28..43e99e0 100644 --- a/api/page.js +++ b/api/page.js @@ -11,30 +11,29 @@ var url = require('url'); * @param {Object} data Data with optional prev and next links. * @param {function(Object):Promise} factory Function that creates a promise of * new data given a query object. + * @param {Object} options Query options. * @constructor * @ignore */ -function Page(data, factory) { +function Page(data, factory, options) { var links = data.links; /** * Get the previous page. If there is no previous page, `prev` will be * `null`. - * @param {Object} options Any request options. * @return {Promise.} The previous page. * @method */ - this.prev = !links.prev ? null : function(options) { + this.prev = !links.prev ? null : function() { return factory(url.parse(links.prev, true).query, options); }; /** * Get the next page. If there is no next page, `next` will be `null`. - * @param {Object} options Any request options. * @return {Promise.} The next page. * @method */ - this.next = !links.next ? null : function(options) { + this.next = !links.next ? null : function() { return factory(url.parse(links.next, true).query, options); }; diff --git a/api/quads.js b/api/quads.js index 1f4dec1..8e074b3 100644 --- a/api/quads.js +++ b/api/quads.js @@ -50,7 +50,7 @@ function search(mosaicId, query, options) { terminator: options.terminator }; return request.get(config).then(function(res) { - return new Page(res.body, search.bind(null, mosaicId)); + return new Page(res.body, search.bind(null, mosaicId), options); }); } diff --git a/api/scenes.js b/api/scenes.js index 190a8ba..480b7a1 100644 --- a/api/scenes.js +++ b/api/scenes.js @@ -64,7 +64,7 @@ function search(query, options) { terminator: options.terminator }; return request.get(config).then(function(res) { - return new Page(res.body, search); + return new Page(res.body, search, options); }); } diff --git a/test/api/page.test.js b/test/api/page.test.js index 83a228e..0fafd67 100644 --- a/test/api/page.test.js +++ b/test/api/page.test.js @@ -63,11 +63,11 @@ describe('api/page', function() { } }; - var page = new Page(data, spy); + var options = {}; + var page = new Page(data, spy, options); assert.typeOf(page.next, 'function'); - var options = {}; - page.next(options); + page.next(); assert.equal(spy.callCount, 1); var call = spy.getCall(0); assert.equal(call.args[1], options); @@ -124,11 +124,11 @@ describe('api/page', function() { } }; - var page = new Page(data, spy); + var options = {}; + var page = new Page(data, spy, options); assert.typeOf(page.prev, 'function'); - var options = {}; - page.prev(options); + page.prev(); assert.equal(spy.callCount, 1); var call = spy.getCall(0); assert.equal(call.args[1], options);