Skip to content

Commit a4ec9d0

Browse files
authored
Merge pull request #34 from ifwe/angular-inject
Add angular wrapper helpers to disable batching
2 parents 99cf223 + c897237 commit a4ec9d0

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

lib/wrappers/angular.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@ function angularWrapper(angular, Monocle) {
1313
this._base = '/';
1414
this._timeout = 30000;
1515
this._headers = {};
16+
this._enableBatching = true;
1617

1718
this.setBase = function(base) {
1819
this._base = base;
1920
};
2021

22+
this.enableBatching = function() {
23+
this._enableBatching = true;
24+
};
25+
26+
this.disableBatching = function() {
27+
this._enableBatching = false;
28+
};
29+
2130
this.setTimeout = function(timeout) {
2231
this._timeout = parseInt(timeout, 10) || 30000;
2332
};
@@ -34,6 +43,9 @@ function angularWrapper(angular, Monocle) {
3443

3544
var monocle = new Monocle(angularAdapter, $q);
3645
monocle.setBase(this._base);
46+
if (!this._enableBatching) {
47+
monocle.disableBatching();
48+
}
3749

3850
// Wrap all promises in Angular promises
3951
['get', 'post', 'put', 'patch', 'delete', 'options'].forEach(function(method) {

monocle-client-angular-min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

monocle-client-angular.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,11 +3519,20 @@ function angularWrapper(angular, Monocle) {
35193519
this._base = '/';
35203520
this._timeout = 30000;
35213521
this._headers = {};
3522+
this._enableBatching = true;
35223523

35233524
this.setBase = function(base) {
35243525
this._base = base;
35253526
};
35263527

3528+
this.enableBatching = function() {
3529+
this._enableBatching = true;
3530+
};
3531+
3532+
this.disableBatching = function() {
3533+
this._enableBatching = false;
3534+
};
3535+
35273536
this.setTimeout = function(timeout) {
35283537
this._timeout = parseInt(timeout, 10) || 30000;
35293538
};
@@ -3540,6 +3549,9 @@ function angularWrapper(angular, Monocle) {
35403549

35413550
var monocle = new Monocle(angularAdapter, $q);
35423551
monocle.setBase(this._base);
3552+
if (!this._enableBatching) {
3553+
monocle.disableBatching();
3554+
}
35433555

35443556
// Wrap all promises in Angular promises
35453557
['get', 'post', 'put', 'patch', 'delete', 'options'].forEach(function(method) {

test/unit/lib/wrappers/angular_test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ describe('Angular Wrapper', function() {
1919

2020
this.Monocle = sinon.spy();
2121
this.Monocle.prototype.setBase = sinon.spy();
22+
this.Monocle.prototype.disableBatching = sinon.spy();
23+
this.Monocle.prototype.enableBatching = sinon.spy();
2224

2325
wrapper(this.angular, this.Monocle);
2426
});
@@ -60,5 +62,49 @@ describe('Angular Wrapper', function() {
6062
var api = provider.$get($http, $q, $window);
6163
this.Monocle.prototype.setBase.calledWith('/test').should.be.true;
6264
});
65+
66+
it('does not disable batching by default', function() {
67+
var $http = {};
68+
var $q = {};
69+
var $window = {};
70+
var provider = new (this.providers.monocle)();
71+
var api = provider.$get($http, $q, $window);
72+
this.Monocle.prototype.enableBatching.called.should.be.false;
73+
this.Monocle.prototype.disableBatching.called.should.be.false;
74+
});
75+
76+
it('can en batching', function() {
77+
var $http = {};
78+
var $q = {};
79+
var $window = {};
80+
var provider = new (this.providers.monocle)();
81+
provider.disableBatching();
82+
var api = provider.$get($http, $q, $window);
83+
this.Monocle.prototype.enableBatching.called.should.be.false;
84+
this.Monocle.prototype.disableBatching.called.should.be.true;
85+
});
86+
87+
it('can disable batching', function() {
88+
var $http = {};
89+
var $q = {};
90+
var $window = {};
91+
var provider = new (this.providers.monocle)();
92+
provider.disableBatching();
93+
var api = provider.$get($http, $q, $window);
94+
this.Monocle.prototype.enableBatching.called.should.be.false;
95+
this.Monocle.prototype.disableBatching.called.should.be.true;
96+
});
97+
98+
it('can disable and re-enable batching', function() {
99+
var $http = {};
100+
var $q = {};
101+
var $window = {};
102+
var provider = new (this.providers.monocle)();
103+
provider.disableBatching();
104+
provider.enableBatching();
105+
var api = provider.$get($http, $q, $window);
106+
this.Monocle.prototype.enableBatching.called.should.be.false;
107+
this.Monocle.prototype.disableBatching.called.should.be.false;
108+
});
63109
});
64110
});

0 commit comments

Comments
 (0)