Skip to content

Commit c21aa6f

Browse files
Merge pull request #59 from kuzzleio/KUZ415_serialize
renamed KuzzleDocument.toJSON to serialize
2 parents 7b00102 + c89bfdd commit c21aa6f

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

dist/kuzzle.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,
16441644
}
16451645

16461646
if (document instanceof KuzzleDocument) {
1647-
data = document.toJSON();
1647+
data = document.serialize();
16481648
} else {
16491649
data.body = document;
16501650
}
@@ -1849,7 +1849,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options) {
18491849
var data = {};
18501850

18511851
if (document instanceof KuzzleDocument) {
1852-
data = document.toJSON();
1852+
data = document.serialize();
18531853
} else {
18541854
data.body = document;
18551855
}
@@ -2313,7 +2313,7 @@ function KuzzleDocument(kuzzleDataCollection, documentId, content) {
23132313
*
23142314
* @return {object} JSON object representing this document
23152315
*/
2316-
KuzzleDocument.prototype.toJSON = function () {
2316+
KuzzleDocument.prototype.serialize = function () {
23172317
var
23182318
data = {};
23192319

@@ -2334,7 +2334,7 @@ KuzzleDocument.prototype.toJSON = function () {
23342334
* @return {string} serialized version of this object
23352335
*/
23362336
KuzzleDocument.prototype.toString = function () {
2337-
return JSON.stringify(this.toJSON());
2337+
return JSON.stringify(this.serialize());
23382338
};
23392339

23402340
/**
@@ -2361,15 +2361,15 @@ KuzzleDocument.prototype.delete = function (options, cb) {
23612361
}
23622362

23632363
if (cb) {
2364-
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.toJSON(), options, function (err) {
2364+
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options, function (err) {
23652365
if (err) {
23662366
return cb(err);
23672367
}
23682368

23692369
cb(null, self);
23702370
});
23712371
} else {
2372-
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.toJSON(), options);
2372+
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options);
23732373
}
23742374

23752375
return this;
@@ -2427,7 +2427,7 @@ KuzzleDocument.prototype.refresh = function (options, cb) {
24272427
*/
24282428
KuzzleDocument.prototype.save = function (options, cb) {
24292429
var
2430-
data = this.toJSON(),
2430+
data = this.serialize(),
24312431
self = this;
24322432

24332433
if (options && cb === undefined && typeof options === 'function') {
@@ -2462,7 +2462,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
24622462
* @returns {*} this
24632463
*/
24642464
KuzzleDocument.prototype.publish = function (options) {
2465-
var data = this.toJSON();
2465+
var data = this.serialize();
24662466

24672467
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'publish'), data, options);
24682468

dist/kuzzle.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.

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.

src/kuzzleDataCollection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ KuzzleDataCollection.prototype.createDocument = function (id, document, options,
213213
}
214214

215215
if (document instanceof KuzzleDocument) {
216-
data = document.toJSON();
216+
data = document.serialize();
217217
} else {
218218
data.body = document;
219219
}
@@ -418,7 +418,7 @@ KuzzleDataCollection.prototype.publishMessage = function (document, options) {
418418
var data = {};
419419

420420
if (document instanceof KuzzleDocument) {
421-
data = document.toJSON();
421+
data = document.serialize();
422422
} else {
423423
data.body = document;
424424
}

src/kuzzleDocument.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function KuzzleDocument(kuzzleDataCollection, documentId, content) {
9999
*
100100
* @return {object} JSON object representing this document
101101
*/
102-
KuzzleDocument.prototype.toJSON = function () {
102+
KuzzleDocument.prototype.serialize = function () {
103103
var
104104
data = {};
105105

@@ -120,7 +120,7 @@ KuzzleDocument.prototype.toJSON = function () {
120120
* @return {string} serialized version of this object
121121
*/
122122
KuzzleDocument.prototype.toString = function () {
123-
return JSON.stringify(this.toJSON());
123+
return JSON.stringify(this.serialize());
124124
};
125125

126126
/**
@@ -147,15 +147,15 @@ KuzzleDocument.prototype.delete = function (options, cb) {
147147
}
148148

149149
if (cb) {
150-
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.toJSON(), options, function (err) {
150+
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options, function (err) {
151151
if (err) {
152152
return cb(err);
153153
}
154154

155155
cb(null, self);
156156
});
157157
} else {
158-
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.toJSON(), options);
158+
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'delete'), this.serialize(), options);
159159
}
160160

161161
return this;
@@ -213,7 +213,7 @@ KuzzleDocument.prototype.refresh = function (options, cb) {
213213
*/
214214
KuzzleDocument.prototype.save = function (options, cb) {
215215
var
216-
data = this.toJSON(),
216+
data = this.serialize(),
217217
self = this;
218218

219219
if (options && cb === undefined && typeof options === 'function') {
@@ -248,7 +248,7 @@ KuzzleDocument.prototype.save = function (options, cb) {
248248
* @returns {*} this
249249
*/
250250
KuzzleDocument.prototype.publish = function (options) {
251-
var data = this.toJSON();
251+
var data = this.serialize();
252252

253253
this.kuzzle.query(this.dataCollection.buildQueryArgs('write', 'publish'), data, options);
254254

test/kuzzleDocument/methods.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ describe('KuzzleDocument methods', function () {
5757
it('should serialize itself properly', function () {
5858
var
5959
document = new KuzzleDocument(dataCollection, {some: 'content'}),
60-
serialized = document.toJSON();
60+
serialized = document.serialize();
6161

6262
should(serialized._id).be.undefined();
6363
should(serialized._version).be.undefined();
6464
should(serialized.body).be.an.Object().and.match({some: 'content'});
6565

6666
document.id = 'foo';
67-
serialized = document.toJSON();
67+
serialized = document.serialize();
6868
should(serialized._id).be.exactly('foo');
6969
should(serialized._version).be.undefined();
7070
should(serialized.body).be.an.Object().and.match({some: 'content'});
7171

7272
document.version = 42;
73-
serialized = document.toJSON();
73+
serialized = document.serialize();
7474
should(serialized._id).be.exactly('foo');
7575
should(serialized._version).be.exactly(42);
7676
should(serialized.body).be.an.Object().and.match({some: 'content'});
@@ -86,7 +86,7 @@ describe('KuzzleDocument methods', function () {
8686
it('should stringify itself properly', function () {
8787
var
8888
document = new KuzzleDocument(dataCollection, 'id', {some: 'content', _version: 42}),
89-
serialized = document.toJSON(),
89+
serialized = document.serialize(),
9090
stringified = document.toString();
9191

9292
should(stringified).be.a.String();

0 commit comments

Comments
 (0)