Skip to content

Commit e5b3318

Browse files
committed
Merge pull request #13 from kuzzleio/promisifyRefactor
promisify only what's needed
2 parents 418e120 + df96457 commit e5b3318

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

src/kuzzle.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,14 @@ module.exports = Kuzzle = function (url, options, cb) {
205205
construct.call(this, url, cb);
206206

207207
if (this.bluebird) {
208-
return this.bluebird.promisifyAll(this, {suffix: 'Promise'});
208+
return this.bluebird.promisifyAll(this, {
209+
suffix: 'Promise',
210+
filter: function (name, func, target, passes) {
211+
var whitelist = ['getAllStatistics', 'getStatistics', 'listCollections', 'now', 'query'];
212+
213+
return passes && whitelist.indexOf(name) !== -1;
214+
}
215+
});
209216
}
210217

211218
return this;

src/kuzzleDataCollection.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ function KuzzleDataCollection(kuzzle, collection) {
3838
});
3939

4040
if (this.kuzzle.bluebird) {
41-
return this.kuzzle.bluebird.promisifyAll(this, {suffix: 'Promise'});
41+
return this.kuzzle.bluebird.promisifyAll(this, {
42+
suffix: 'Promise',
43+
filter: function (name, func, target, passes) {
44+
var blacklist = ['publish', 'setHeaders', 'subscribe'];
45+
46+
return passes && blacklist.indexOf(name) === -1;
47+
}
48+
});
4249
}
4350

4451
return this;

src/kuzzleDataMapping.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ function KuzzleDataMapping(kuzzleDataCollection) {
4343
});
4444

4545
if (this.kuzzle.bluebird) {
46-
return this.kuzzle.bluebird.promisifyAll(this, {suffix: 'Promise'});
46+
return this.kuzzle.bluebird.promisifyAll(this, {
47+
suffix: 'Promise',
48+
filter: function (name, func, target, passes) {
49+
var blacklist = ['set', 'setHeaders'];
50+
51+
return passes && blacklist.indexOf(name) === -1;
52+
}
53+
});
4754
}
4855

4956
return this;

src/kuzzleDocument.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ function KuzzleDocument(kuzzleDataCollection, documentId, content) {
9494

9595
// promisifying
9696
if (this.kuzzle.bluebird) {
97-
return this.kuzzle.bluebird.promisifyAll(this, {suffix: 'Promise'});
97+
return this.kuzzle.bluebird.promisifyAll(this, {
98+
suffix: 'Promise',
99+
filter: function (name, func, target, passes) {
100+
var whitelist = ['delete', 'refresh', 'save'];
101+
102+
return passes && whitelist.indexOf(name) !== -1;
103+
}
104+
});
98105
}
99106

100107
return this;

src/kuzzleRoom.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ function KuzzleRoom(kuzzleDataCollection, options) {
9696
});
9797

9898
if (this.kuzzle.bluebird) {
99-
return this.kuzzle.bluebird.promisifyAll(this, {suffix: 'Promise'});
99+
return this.kuzzle.bluebird.promisifyAll(this, {
100+
suffix: 'Promise',
101+
filter: function (name, func, target, passes) {
102+
var whitelist = ['count'];
103+
104+
return passes && whitelist.indexOf(name) !== -1;
105+
}
106+
});
100107
}
101108

102109
return this;

0 commit comments

Comments
 (0)