Skip to content

Commit d9c6c8f

Browse files
authored
Merge pull request #97 from kuzzleio/publishMessageCB
Add callback to KuzzleDataCollection.publishMessage
2 parents 5ad2981 + 028213a commit d9c6c8f

File tree

5 files changed

+19
-40
lines changed

5 files changed

+19
-40
lines changed

dist/kuzzle.js

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,12 @@
22
// shim for using process in browser
33

44
var process = module.exports = {};
5-
6-
// cached from whatever global is present so that test runners that stub it
7-
// don't break things. But we need to wrap it in a try catch in case it is
8-
// wrapped in strict mode code which doesn't define any globals. It's inside a
9-
// function because try/catches deoptimize in certain engines.
10-
11-
var cachedSetTimeout;
12-
var cachedClearTimeout;
13-
14-
(function () {
15-
try {
16-
cachedSetTimeout = setTimeout;
17-
} catch (e) {
18-
cachedSetTimeout = function () {
19-
throw new Error('setTimeout is not defined');
20-
}
21-
}
22-
try {
23-
cachedClearTimeout = clearTimeout;
24-
} catch (e) {
25-
cachedClearTimeout = function () {
26-
throw new Error('clearTimeout is not defined');
27-
}
28-
}
29-
} ())
305
var queue = [];
316
var draining = false;
327
var currentQueue;
338
var queueIndex = -1;
349

3510
function cleanUpNextTick() {
36-
if (!draining || !currentQueue) {
37-
return;
38-
}
3911
draining = false;
4012
if (currentQueue.length) {
4113
queue = currentQueue.concat(queue);
@@ -51,7 +23,7 @@ function drainQueue() {
5123
if (draining) {
5224
return;
5325
}
54-
var timeout = cachedSetTimeout(cleanUpNextTick);
26+
var timeout = setTimeout(cleanUpNextTick);
5527
draining = true;
5628

5729
var len = queue.length;
@@ -68,7 +40,7 @@ function drainQueue() {
6840
}
6941
currentQueue = null;
7042
draining = false;
71-
cachedClearTimeout(timeout);
43+
clearTimeout(timeout);
7244
}
7345

7446
process.nextTick = function (fun) {
@@ -80,7 +52,7 @@ process.nextTick = function (fun) {
8052
}
8153
queue.push(new Item(fun, args));
8254
if (queue.length === 1 && !draining) {
83-
cachedSetTimeout(drainQueue, 0);
55+
setTimeout(drainQueue, 0);
8456
}
8557
};
8658

@@ -2245,9 +2217,10 @@ KuzzleDataCollection.prototype.getMapping = function (options, cb) {
22452217
*
22462218
* @param {object} document - either a KuzzleDocument instance or a JSON object
22472219
* @param {object} [options] - optional arguments
2220+
* @param {responseCallback} [cb] - Returns a raw Kuzzle response
22482221
* @returns {*} this
22492222
*/
2250-
KuzzleDataCollection.prototype.publishMessage = function (document, options) {
2223+
KuzzleDataCollection.prototype.publishMessage = function (document, options, cb) {
22512224
var data = {};
22522225

22532226
if (document instanceof KuzzleDocument) {
@@ -2257,7 +2230,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options) {
22572230
}
22582231

22592232
data = this.kuzzle.addHeaders(data, this.headers);
2260-
this.kuzzle.query(this.buildQueryArgs('write', 'publish'), data, options);
2233+
this.kuzzle.query(this.buildQueryArgs('write', 'publish'), data, options, cb);
22612234

22622235
return this;
22632236
};
@@ -2566,6 +2539,11 @@ KuzzleDataMapping.prototype.refresh = function (options, cb) {
25662539
if (res.result[self.collection.index]) {
25672540
if (res.result[self.collection.index].mappings[self.collection.collection]) {
25682541
self.mapping = res.result[self.collection.index].mappings[self.collection.collection].properties;
2542+
2543+
// Mappings can be empty. The mapping property should never be "undefined"
2544+
if (self.mapping === undefined) {
2545+
self.mapping = {};
2546+
}
25692547
} else {
25702548
return cb ? cb(new Error('No mapping found for collection ' + self.collection.collection)) : false;
25712549
}

dist/kuzzle.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/kuzzle.min.map

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kuzzle-sdk",
3-
"version": "1.9.2",
3+
"version": "1.9.3",
44
"description": "Official Javascript SDK for Kuzzle",
55
"author": "The Kuzzle Team <[email protected]>",
66
"repository": {

src/kuzzleDataCollection.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,10 @@ KuzzleDataCollection.prototype.getMapping = function (options, cb) {
402402
*
403403
* @param {object} document - either a KuzzleDocument instance or a JSON object
404404
* @param {object} [options] - optional arguments
405+
* @param {responseCallback} [cb] - Returns a raw Kuzzle response
405406
* @returns {*} this
406407
*/
407-
KuzzleDataCollection.prototype.publishMessage = function (document, options) {
408+
KuzzleDataCollection.prototype.publishMessage = function (document, options, cb) {
408409
var data = {};
409410

410411
if (document instanceof KuzzleDocument) {
@@ -414,7 +415,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options) {
414415
}
415416

416417
data = this.kuzzle.addHeaders(data, this.headers);
417-
this.kuzzle.query(this.buildQueryArgs('write', 'publish'), data, options);
418+
this.kuzzle.query(this.buildQueryArgs('write', 'publish'), data, options, cb);
418419

419420
return this;
420421
};

0 commit comments

Comments
 (0)