Comparing version 0.0.6 to 0.0.7
@@ -34,6 +34,2 @@ /* | ||
var _requests = [], | ||
_requestSpecificCallbacks = [], | ||
_requestExtensionData = []; | ||
/** | ||
@@ -59,2 +55,7 @@ * Initialise Batchelor | ||
// Ready internal variables | ||
this._requests = []; | ||
this._requestSpecificCallbacks = []; | ||
this._requestExtensionData = []; | ||
// Chaining baby | ||
@@ -93,3 +94,3 @@ return this; | ||
if (!!options.callback) { | ||
_requestSpecificCallbacks[requestId] = options.callback; | ||
this._requestSpecificCallbacks[requestId] = options.callback; | ||
} | ||
@@ -99,3 +100,3 @@ | ||
if (!!options.extend) { | ||
_requestExtensionData[requestId] = options.extend; | ||
this._requestExtensionData[requestId] = options.extend; | ||
} | ||
@@ -122,3 +123,3 @@ | ||
// Push to _requests Array | ||
_requests.push(options); | ||
this._requests.push(options); | ||
@@ -138,6 +139,7 @@ // Chaining baby | ||
var _multiparts = []; | ||
var _multiparts = [], | ||
_self = this; | ||
// Build multipart request | ||
_requests.forEach(function (requestPart) { | ||
this._requests.forEach(function (requestPart) { | ||
@@ -222,4 +224,4 @@ var requestSettings = { | ||
var returnedContentId = part.header['content-id'], | ||
currentRequestCallback = null, | ||
currentRequestExtendData = null; | ||
currentRequestCallback, | ||
currentRequestExtendData; | ||
@@ -236,6 +238,6 @@ if (!!returnedContentId) { | ||
// As we have a content id, we can link to individual callback (if exists) | ||
currentRequestCallback = _requestSpecificCallbacks[returnedContentId]; | ||
currentRequestCallback = _self._requestSpecificCallbacks[returnedContentId]; | ||
// If this request has extend data, retrieve it for callback | ||
currentRequestExtendData = _requestExtensionData[returnedContentId]; | ||
currentRequestExtendData = _self._requestExtensionData[returnedContentId]; | ||
} | ||
@@ -258,10 +260,4 @@ | ||
// Extend data sent through as is for parse in callback | ||
callback(responseBody, _requestExtensionData); | ||
callback(responseBody, _self._requestExtensionData); | ||
// Clean up | ||
_requests = []; | ||
_requestExtensionData = []; | ||
_requestSpecificCallbacks = []; | ||
_multiparts = []; | ||
}); | ||
@@ -274,2 +270,18 @@ | ||
/** | ||
* Reset all internal options if a re-run is required | ||
* | ||
* @return {object} Batchelor object | ||
*/ | ||
Batchelor.reset = function () { | ||
this._requests = []; | ||
this._requestSpecificCallbacks = []; | ||
this._requestExtensionData = []; | ||
this._globalOptions.multipart = []; | ||
return this; | ||
}; | ||
}(exports)); |
{ | ||
"name": "batchelor", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "A lovely little Node.js module to perform batch requests with the Google REST API", | ||
@@ -5,0 +5,0 @@ "main": "./lib/batchelor", |
@@ -138,9 +138,22 @@ # Batchelor | ||
###### Resetting and Re-using | ||
Once Batchelor has been run, there are certain use-cases for running futher batch requests on response. This requires the variables in the module to be reset. This can be done using the `.reset()` call: | ||
``` node | ||
Batchelor.run(function(response){ | ||
// Reset Batchelor for further use | ||
Batchelor.reset(); | ||
... | ||
}); | ||
``` | ||
## To Do List-ish | ||
These might get done if we end up needing them/have time: | ||
* Limit requests per batch request | ||
* Handle Media in API calls (no need for it here, feel free) | ||
* Handle Media in API calls (no need for it here, feel free to write it) | ||
## Release History | ||
* 0.0.7 Reset function for when you are using batchelor more than once in a script (ability for nested requests too) | ||
* 0.0.6 Bug fixes introduced in the last update and clean up was happening too soon. Moved it. | ||
@@ -147,0 +160,0 @@ * 0.0.5 Added the ability to passthrough specific information from the `.add()` options to the response object |
15970
208
167