-
Notifications
You must be signed in to change notification settings - Fork 28
Home
JMBattista edited this page Oct 8, 2015
·
1 revision
Welcome to the angular-http-batcher wiki!
When working with angular-http-batcher you may sometimes want to disable batching for debug / testing purposes. The recommended way to do this is with the enabled flag in the configuration options (see: https://github.com/jonsamwell/angular-http-batcher/issues/13)
// constant set in a different module
angular.module('myApp.constants', [])
.constant('enableBatching', true);
angular.module('myApp', ['myApp.constants', 'jcs.angular-http-batch'])
.config([
'httpBatchConfigProvider', 'enableBatching',
function (httpBatchConfigProvider, 'enableBatching') {
httpBatchConfigProvider.setAllowedBatchEndpoint(
// root endpoint url
'http://api.myapp.com',
// endpoint batch address
'http://api.myapp.com/batch',
// optional configuration parameters
{
// the enabled flag
enabled: enableBatching
maxBatchedRequestPerCall: 20
});
}
]);
By setting the enabled flag via a constant you can easily change it for debugging, but you can also disable the batcher when performing unit tests using the following pattern in your test setup. By placing the constant in a separate module we are able to override the constant before loading the module that contains the config block (which is run immediately).
// import the constants module
beforeEach(module('myApp.constants'));
// override the constant
beforeEach(function() {
module(function($provide) {
$provide.constant('enableBatching', false);
});
});
// load the module that contains the config block
beforeEach(module('myApp') ....