From b555463a906ac8b24c07f6c947106a057c2173fe Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Fri, 25 Jul 2014 13:21:02 -0500 Subject: [PATCH] Minor cleanup in SearchPager --- lib/client/client.js | 2 +- lib/client/search_pager.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/client/client.js b/lib/client/client.js index f29438d..6720320 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -810,7 +810,7 @@ Client.prototype.search = function search(base, size = pageOpts.pageSize; } else if (options.sizeLimit > 1) { // According to the RFC, servers should ignore the paging control if - // pageSize >= sizelimit. Some will still send results, but it's safer + // pageSize >= sizelimit. Some might still send results, but it's safer // to stay under that figure when assigning a default value. size = options.sizeLimit - 1; } diff --git a/lib/client/search_pager.js b/lib/client/search_pager.js index da6568d..9eb87ca 100644 --- a/lib/client/search_pager.js +++ b/lib/client/search_pager.js @@ -81,16 +81,18 @@ SearchPager.prototype._onEntry = function _onEntry(entry) { SearchPager.prototype._onEnd = function _onEnd(res) { var self = this; var cookie = null; - var nullFunc = function () { }; res.controls.forEach(function (control) { if (control.type === PagedControl.OID) { cookie = control.value.cookie; } }); + // Pass a noop callback by default for page events + var nullCb = function () { }; + if (cookie === null) { // paged search not supported this.finished = true; - this.emit('page', res, nullFunc); + this.emit('page', res, nullCb); var err = new Error('missing paged control'); err.name = 'PagedError'; if (this.listeners('pageError') > 0) { @@ -104,10 +106,13 @@ SearchPager.prototype._onEnd = function _onEnd(res) { this.emit('error', err); // No end event possible per explaination above. } - } else if (cookie.length === 0) { + return; + } + + if (cookie.length === 0) { // end of paged results this.finished = true; - this.emit('page', nullFunc); + this.emit('page', nullCb); this.emit('end', res); } else { if (this.pagePause) { @@ -122,7 +127,7 @@ SearchPager.prototype._onEnd = function _onEnd(res) { } }); } else { - this.emit('page', res, nullFunc); + this.emit('page', res, nullCb); this._nextPage(cookie); } }