An easy interface to queue up all the XHR requests on the page and display the response of each call by grouping them as an atomic operation.
This helps avoiding the data flickering on the page. This API uses $q module of Angular.
This API also provides a support to perform any callback task after the request queue is done processing i.e hiding page loader etc.
// Example 1
// Queue up all the calls and process when everything is done
// with this approach, all response will be rendered once everything is completed i.e queue is empty.
RequestQueue.enqueue([
vm.getFirstObject(4),
vm.getSecondObject(5),
vm.getThirdObject({key:111})
],
$scope.handlePageLoader).process().then(function(result) {
// response will be returned in call seq
$scope.first.push(result[0]);
$scope.second = result[1];
$scope.third.push(result[2]);
});
// Example 2
// Queue up all the calls and keep processing(rendering) the response as and when response is ready for the view.
// This is possible via passing the mapper functions i.e response handlers for each remote call.
RequestQueue.enqueue([
$scope.getFirstObject(),
$scope.getSecondObject(),
],
$scope.handlePageLoader, "QueueName").processAndMap([ $scope.responseHandlerFirstObject, $scope.responseHandlerSecondObject]);
Init the Request Queue
Type: 'Function'
To hide the loader when queue is done.
Type: String
A name for the queue.
RequestQueue([arrayOfRemoteCallFunctions], callback, queueKey).process().then(promiseArray) {
...
}
###NOTE This is a very initial version of this API, I am very much open for suggestions/improvements. Feel free to contribute by forking, opening issues, pull requests etc.
GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007