Comparing version 0.3.8 to 0.3.9
@@ -311,3 +311,3 @@ 'use strict'; | ||
value: function findOne(query, sortObj) { | ||
return new _Cursor2['default'](this, query).sort(sortObj).limit(1).exec().then(function (docs) { | ||
return this.find(query).sort(sortObj).limit(1).aggregate(function (docs) { | ||
return docs[0]; | ||
@@ -314,0 +314,0 @@ }); |
@@ -23,2 +23,6 @@ 'use strict'; | ||
var _lodashLangIsArray = require('lodash/lang/isArray'); | ||
var _lodashLangIsArray2 = _interopRequireDefault(_lodashLangIsArray); | ||
var _Cursor2 = require('./Cursor'); | ||
@@ -156,5 +160,3 @@ | ||
_this2._latestResult = result; | ||
_this2._latestIds = new Set(result.map(function (x) { | ||
return x._id; | ||
})); | ||
_this2._updateLatestIds(); | ||
_this2._propagateUpdate(firstRun); | ||
@@ -233,2 +235,18 @@ return result; | ||
} | ||
/** | ||
* By a `_latestResult` update a `_latestIds` field of | ||
* the object | ||
*/ | ||
}, { | ||
key: '_updateLatestIds', | ||
value: function _updateLatestIds() { | ||
if ((0, _lodashLangIsArray2['default'])(this._latestResult)) { | ||
this._latestIds = new Set(this._latestResult.map(function (x) { | ||
return x._id; | ||
})); | ||
} else if (this._latestResult && this._latestResult._id) { | ||
this._latestIds = new Set([this._latestResult._id]); | ||
} | ||
} | ||
}]); | ||
@@ -235,0 +253,0 @@ |
@@ -253,7 +253,5 @@ import EventEmitter from 'eventemitter3'; | ||
findOne(query, sortObj) { | ||
return new Cursor(this, query) | ||
return this.find(query) | ||
.sort(sortObj).limit(1) | ||
.exec().then((docs) => { | ||
return docs[0]; | ||
}); | ||
.aggregate(docs => docs[0]); | ||
} | ||
@@ -260,0 +258,0 @@ |
import _size from 'lodash/collection/size'; | ||
import _isArray from 'lodash/lang/isArray'; | ||
import Cursor from './Cursor'; | ||
@@ -97,3 +98,3 @@ import EJSON from './EJSON'; | ||
this._latestResult = result; | ||
this._latestIds = new Set(result.map(x => x._id)); | ||
this._updateLatestIds(); | ||
this._propagateUpdate(firstRun); | ||
@@ -182,2 +183,14 @@ return result; | ||
} | ||
/** | ||
* By a `_latestResult` update a `_latestIds` field of | ||
* the object | ||
*/ | ||
_updateLatestIds() { | ||
if (_isArray(this._latestResult)) { | ||
this._latestIds = new Set(this._latestResult.map(x => x._id)); | ||
} else if (this._latestResult && this._latestResult._id) { | ||
this._latestIds = new Set([this._latestResult._id]); | ||
} | ||
} | ||
} | ||
@@ -184,0 +197,0 @@ |
{ | ||
"name": "marsdb", | ||
"version": "0.3.8", | ||
"version": "0.3.9", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Artem Artemev", |
@@ -226,2 +226,18 @@ import Collection from '../../lib/Collection'; | ||
}); | ||
it('should observe `findOne` collection method', function (done) { | ||
var calls = 0; | ||
db.findOne({b: 8}).batchSize(1).debounce(0) | ||
.observe(result => { | ||
calls += 1; | ||
if (calls === 1) { | ||
expect(result).to.be.undefined; | ||
} else if (calls > 1) { | ||
result.b.should.be.equals(8); | ||
done(); | ||
} | ||
}).then(() => { | ||
db.insert({b: 8}); | ||
}); | ||
}); | ||
}); | ||
@@ -228,0 +244,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1072199
25008