@@ -5,9 +5,6 @@ var PageError = require('../errors/page');
55/**
66 * @method page
77 * @description
8- * **Alternative Syntax:**
9- * `page(source, {dest, limit})` ⇒ `Promise`
10- *
118 * Resolves a dynamic sequence of pages/arrays with [mixed values]{@tutorial mixed}.
129 *
1310 * The method acquires pages (arrays of [mixed values]{@tutorial mixed}) from the `source` function, one by one,
@@ -33,7 +30,10 @@ var PageError = require('../errors/page');
3330 *
3431 * Passing in anything other than a function will reject with {@link external:TypeError TypeError} = `Parameter 'source' must be a function.`
3532 *
36- * @param {Function|generator } [dest]
33+ * @param {Object } [options]
34+ * Optional Parameters.
35+ *
36+ * @param {Function|generator } [options.dest]
3737 * Optional destination function (or generator), to receive a resolved {@link batch} of data
3838 * for each page, process it and respond as required.
3939 *
@@ -51,7 +51,7 @@ var PageError = require('../errors/page');
5151 * If the function throws an error or returns a rejected promise, the sequence terminates,
5252 * and the method rejects with {@link errors.PageError PageError}, which will have property `dest` set.
5353 *
54- * @param {Number } [limit=0]
54+ * @param {Number } [options. limit=0]
5555 * Limits the maximum number of pages to be requested from the `source`. If the value is greater
5656 * than 0, the method will successfully resolve once the specified limit has been reached.
5757 *
@@ -70,19 +70,21 @@ var PageError = require('../errors/page');
7070 * When the method fails, it rejects with {@link errors.PageError PageError}.
7171 *
7272 */
73- function page ( source , dest , limit , config ) {
73+ function page ( source , options , config ) {
7474
7575 var $p = config . promise , $spex = config . spex , $utils = config . utils ;
7676
7777 if ( typeof source !== 'function' ) {
7878 return $p . reject ( new TypeError ( 'Parameter \'source\' must be a function.' ) ) ;
7979 }
8080
81- limit = ( limit > 0 ) ? parseInt ( limit ) : 0 ;
81+ options = options || { } ;
8282 source = $utils . wrap ( source ) ;
83- dest = $utils . wrap ( dest ) ;
8483
85- var self = this , request , srcTime , destTime , start = Date . now ( ) , total = 0 ;
84+ var request , srcTime , destTime ,
85+ limit = ( options . limit > 0 ) ? parseInt ( options . limit ) : 0 ,
86+ dest = $utils . wrap ( options . dest ) ,
87+ self = this , start = Date . now ( ) , total = 0 ;
8688
8789 return $p ( function ( resolve , reject ) {
8890
@@ -176,10 +178,7 @@ function page(source, dest, limit, config) {
176178}
177179
178180module . exports = function ( config ) {
179- return function ( source , dest , limit ) {
180- if ( dest && typeof dest === 'object' ) {
181- return page . call ( this , source , dest . dest , dest . limit , config ) ;
182- }
183- return page . call ( this , source , dest , limit , config ) ;
181+ return function ( source , options ) {
182+ return page . call ( this , source , options , config ) ;
184183 } ;
185184} ;
0 commit comments