Skip to content

Commit 7cdfaab

Browse files
Merge pull request #109 from kuzzleio/kuz-663-kuzzledatacollection-constructor
KUZ-663: KuzzleDataCollection constructor signature
2 parents 8869fa5 + 2894219 commit 7cdfaab

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
*__note:__ the # at the end of lines are the pull request numbers on GitHub*
22

3+
# Current
4+
5+
## Breaking Changes
6+
7+
* `KuzzleDataCollection` constructor signature has been changed from:
8+
`KuzzleDataCollection(kuzzle, index, collection)`
9+
to:
10+
`KuzzleDataCollection(kuzzle, collection, index)`
11+
This has been done to make it on par with the `Kuzzle.dataCollectionFactory` method
12+
313
# 2.0.3
414

515
* https://github.com/kuzzleio/sdk-javascript/releases/tag/2.0.3

src/kuzzle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ Kuzzle.prototype.dataCollectionFactory = function(collection, index) {
896896
}
897897

898898
if (!this.collections[index][collection]) {
899-
this.collections[index][collection] = new KuzzleDataCollection(this, index, collection);
899+
this.collections[index][collection] = new KuzzleDataCollection(this, collection, index);
900900
}
901901

902902
return this.collections[index][collection];

src/kuzzleDataCollection.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,15 @@ var
1515
* A data collection is a set of data managed by Kuzzle. It acts like a data table for persistent documents,
1616
* or like a room for pub/sub messages.
1717
* @param {object} kuzzle - Kuzzle instance to inherit from
18-
* @param {string} index - Index containing the data collection
1918
* @param {string} collection - name of the data collection to handle
19+
* @param {string} index - Index containing the data collection
2020
* @constructor
2121
*/
22-
function KuzzleDataCollection(kuzzle, index, collection) {
22+
function KuzzleDataCollection(kuzzle, collection, index) {
2323
if (!index || !collection) {
2424
throw new Error('The KuzzleDataCollection object constructor needs an index and a collection arguments');
2525
}
2626

27-
2827
Object.defineProperties(this, {
2928
// read-only properties
3029
collection: {

test/kuzzleDataCollection/constructor.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('KuzzleDataCollection constructor', function () {
1414
c;
1515

1616
kuzzle.headers.some = 'headers';
17-
c = new KuzzleDataCollection(kuzzle, index, collection);
17+
c = new KuzzleDataCollection(kuzzle, collection, index);
1818

1919
// the collection "headers" should be a hard copy of the kuzzle ones
2020
kuzzle.headers = { someother: 'headers' };
@@ -38,7 +38,7 @@ describe('KuzzleDataCollection constructor', function () {
3838

3939
Kuzzle.prototype.bluebird = bluebird;
4040
kuzzle = new Kuzzle('foo');
41-
dataCollection = new KuzzleDataCollection(kuzzle, 'foo', 'bar');
41+
dataCollection = new KuzzleDataCollection(kuzzle, 'bar', 'foo');
4242

4343
should.exist(dataCollection.advancedSearchPromise);
4444
should.exist(dataCollection.countPromise);

test/kuzzleDataCollection/methods.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ describe('KuzzleDataCollection methods', function () {
840840

841841
it('should send the right updateDocument query to Kuzzle', function (done) {
842842
var
843-
collection = new KuzzleDataCollection(kuzzle, expectedQuery.index, expectedQuery.collection),
843+
collection = new KuzzleDataCollection(kuzzle, expectedQuery.collection, expectedQuery.index),
844844
options = { queuable: false };
845845
expectedQuery.options = options;
846846

@@ -854,7 +854,7 @@ describe('KuzzleDataCollection methods', function () {
854854
});
855855

856856
it('should handle arguments correctly', function () {
857-
var collection = new KuzzleDataCollection(kuzzle, expectedQuery.index, expectedQuery.collection);
857+
var collection = new KuzzleDataCollection(kuzzle, expectedQuery.collection, expectedQuery.index);
858858

859859
collection.updateDocument('foo');
860860
should(emitted).be.true();
@@ -873,7 +873,7 @@ describe('KuzzleDataCollection methods', function () {
873873
});
874874

875875
it('should call the callback with an error if one occurs', function (done) {
876-
var collection = new KuzzleDataCollection(kuzzle, expectedQuery.index, expectedQuery.collection);
876+
var collection = new KuzzleDataCollection(kuzzle, expectedQuery.collection, expectedQuery.index);
877877
error = 'foobar';
878878
this.timeout(50);
879879

0 commit comments

Comments
 (0)