Comparing version 0.3.10 to 0.3.11
@@ -41,6 +41,2 @@ 'use strict'; | ||
var _Cursor = require('./Cursor'); | ||
var _Cursor2 = _interopRequireDefault(_Cursor); | ||
var _Random = require('./Random'); | ||
@@ -56,2 +52,4 @@ | ||
var _defaultRandomGenerator = new _Random2['default'](); | ||
var _defaultCursorClass = _CursorObservable2['default']; | ||
var _defaultStorageManager = _StorageManager2['default']; | ||
var _defaultIdGenerator = function (modelName) { | ||
@@ -65,3 +63,2 @@ var nextSeed = _defaultRandomGenerator.hexString(20); | ||
}; | ||
var _defaultStorageManager = _StorageManager2['default']; | ||
@@ -300,3 +297,3 @@ var Collection = (function (_EventEmitter) { | ||
value: function find(query) { | ||
return new _CursorObservable2['default'](this, query); | ||
return new _defaultCursorClass(this, query); | ||
} | ||
@@ -346,3 +343,3 @@ | ||
value: function ids(query) { | ||
return new _Cursor2['default'](this, query).ids(); | ||
return new _defaultCursorClass(this, query).ids(); | ||
} | ||
@@ -374,2 +371,7 @@ }, { | ||
} | ||
}, { | ||
key: 'defaultCursorClass', | ||
value: function defaultCursorClass(cursorClass) { | ||
_defaultCursorClass = cursorClass; | ||
} | ||
}]); | ||
@@ -376,0 +378,0 @@ |
@@ -29,5 +29,5 @@ 'use strict'; | ||
var _lodashLangToArray = require('lodash/lang/toArray'); | ||
var _lodashLangIsArray = require('lodash/lang/isArray'); | ||
var _lodashLangToArray2 = _interopRequireDefault(_lodashLangToArray); | ||
var _lodashLangIsArray2 = _interopRequireDefault(_lodashLangIsArray); | ||
@@ -92,3 +92,3 @@ var _lodashLangIsEmpty = require('lodash/lang/isEmpty'); | ||
}), _defineProperty(_PIPELINE_PROCESSORS, PIPELINE_TYPE.JoinEach, function (docs, pipeObj, cursor) { | ||
return Promise.all((0, _lodashLangToArray2['default'])(docs).map(function (x) { | ||
return Promise.all(((0, _lodashLangIsArray2['default'])(docs) ? docs : [docs]).map(function (x) { | ||
return PIPELINE_PROCESSORS[PIPELINE_TYPE.JoinAll](x, pipeObj, cursor); | ||
@@ -98,13 +98,15 @@ })); | ||
var res = pipeObj.value(docs); | ||
if ((0, _lodashLangIsObject2['default'])(res) && res.then) { | ||
if (res.parent) { | ||
res.parent(cursor); | ||
cursor.once('stopped', res.stop); | ||
res = (0, _lodashLangIsArray2['default'])(res) ? res : [res]; | ||
res.forEach(function (observeStopper) { | ||
if ((0, _lodashLangIsObject2['default'])(observeStopper) && observeStopper.then) { | ||
if (observeStopper.parent) { | ||
observeStopper.parent(cursor); | ||
cursor.once('stopped', observeStopper.stop); | ||
cursor.once('cursorChanged', observeStopper.stop); | ||
} | ||
} | ||
return res.then(function () { | ||
return docs; | ||
}); | ||
} else { | ||
}); | ||
return Promise.all(res).then(function () { | ||
return docs; | ||
} | ||
}); | ||
}), _defineProperty(_PIPELINE_PROCESSORS, PIPELINE_TYPE.IfNotEmpty, function (docs) { | ||
@@ -111,0 +113,0 @@ return (0, _lodashLangIsEmpty2['default'])(docs) ? PIPLEINE_STOP_MARKER : docs; |
@@ -210,3 +210,3 @@ 'use strict'; | ||
// When it's an update operation we check three things | ||
// When it's an update operation we check four things | ||
// 1. Is a new doc or old doc matched by a query? | ||
@@ -223,2 +223,3 @@ // 2. Is a new doc has different number of fields then an old doc? | ||
if (insertedInResult) { | ||
this.emit('cursorChanged'); | ||
return this.update(); | ||
@@ -225,0 +226,0 @@ } |
@@ -7,3 +7,2 @@ import EventEmitter from 'eventemitter3'; | ||
import CursorObservable from './CursorObservable'; | ||
import Cursor from './Cursor'; | ||
import Random from './Random'; | ||
@@ -14,4 +13,6 @@ import Document from './Document'; | ||
// Defaults | ||
var _defaultRandomGenerator = new Random(); | ||
var _defaultIdGenerator = function(modelName) { | ||
const _defaultRandomGenerator = new Random(); | ||
let _defaultCursorClass = CursorObservable; | ||
let _defaultStorageManager = StorageManager; | ||
let _defaultIdGenerator = function(modelName) { | ||
const nextSeed = _defaultRandomGenerator.hexString(20); | ||
@@ -24,3 +25,2 @@ const sequenceSeed = [nextSeed, `/collection/${modelName}`]; | ||
}; | ||
var _defaultStorageManager = StorageManager; | ||
@@ -49,2 +49,6 @@ | ||
static defaultCursorClass(cursorClass) { | ||
_defaultCursorClass = cursorClass; | ||
} | ||
get modelName() { | ||
@@ -245,3 +249,3 @@ return this._modelName; | ||
find(query) { | ||
return new CursorObservable(this, query); | ||
return new _defaultCursorClass(this, query); | ||
} | ||
@@ -285,3 +289,3 @@ | ||
ids(query) { | ||
return new Cursor(this, query).ids(); | ||
return new _defaultCursorClass(this, query).ids(); | ||
} | ||
@@ -288,0 +292,0 @@ } |
import _each from 'lodash/collection/each'; | ||
import _isObject from 'lodash/lang/isObject'; | ||
import _toArray from 'lodash/lang/toArray'; | ||
import _isArray from 'lodash/lang/isArray'; | ||
import _isEmpty from 'lodash/lang/isEmpty'; | ||
@@ -49,17 +49,19 @@ import EventEmitter from 'eventemitter3'; | ||
[PIPELINE_TYPE.JoinEach]: (docs, pipeObj, cursor) => { | ||
return Promise.all(_toArray(docs).map( | ||
(x) => PIPELINE_PROCESSORS[PIPELINE_TYPE.JoinAll](x, pipeObj, cursor) | ||
)); | ||
return Promise.all((_isArray(docs) ? docs : [docs]).map((x) => ( | ||
PIPELINE_PROCESSORS[PIPELINE_TYPE.JoinAll](x, pipeObj, cursor) | ||
))); | ||
}, | ||
[PIPELINE_TYPE.JoinAll]: (docs, pipeObj, cursor) => { | ||
const res = pipeObj.value(docs); | ||
if (_isObject(res) && res.then) { | ||
if (res.parent) { | ||
res.parent(cursor); | ||
cursor.once('stopped', res.stop); | ||
let res = pipeObj.value(docs); | ||
res = _isArray(res) ? res : [res]; | ||
res.forEach(observeStopper => { | ||
if (_isObject(observeStopper) && observeStopper.then) { | ||
if (observeStopper.parent) { | ||
observeStopper.parent(cursor); | ||
cursor.once('stopped', observeStopper.stop); | ||
cursor.once('cursorChanged', observeStopper.stop); | ||
} | ||
} | ||
return res.then(() => docs); | ||
} else { | ||
return docs; | ||
} | ||
}); | ||
return Promise.all(res).then(() => docs); | ||
}, | ||
@@ -66,0 +68,0 @@ [PIPELINE_TYPE.IfNotEmpty]: (docs) => { |
@@ -146,3 +146,3 @@ import _size from 'lodash/collection/size'; | ||
// When it's an update operation we check three things | ||
// When it's an update operation we check four things | ||
// 1. Is a new doc or old doc matched by a query? | ||
@@ -174,2 +174,3 @@ // 2. Is a new doc has different number of fields then an old doc? | ||
if (insertedInResult) { | ||
this.emit('cursorChanged'); | ||
return this.update(); | ||
@@ -176,0 +177,0 @@ } |
{ | ||
"name": "marsdb", | ||
"version": "0.3.10", | ||
"version": "0.3.11", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Artem Artemev", |
@@ -146,3 +146,3 @@ import Collection from '../../lib/Collection'; | ||
it('should work nice with observable joins', function (done) { | ||
it('should observe in join and propagate update to upper observer', function (done) { | ||
var calls = 0; | ||
@@ -171,2 +171,29 @@ db.find({$or: [{f: 1}, {f: 2}]}) | ||
it('should stop observing previous join after upper join update', function (done) { | ||
var observerCalls = 0; | ||
var joinCalls = 0; | ||
db.find({$or: [{f: 1}, {f: 2}]}) | ||
.joinAll((docs) => { | ||
return db.find({b: 30}).observe(res => { | ||
if (res.length > 0) { | ||
joinCalls += 1; | ||
joinCalls.should.be.lte(1); | ||
} | ||
}); | ||
}) | ||
.batchSize(0) | ||
.debounce(0) | ||
.observe(result => { | ||
observerCalls.should.be.lte(2); | ||
observerCalls++; | ||
if (observerCalls === 2) { | ||
done(); | ||
} | ||
}).then(() => { | ||
return db.insert({f: 1}); | ||
}).then(() => { | ||
return db.insert({b: 30}); | ||
}); | ||
}); | ||
it('should not update a cursor when updated dcc does not match a query', function (done) { | ||
@@ -173,0 +200,0 @@ var calls = 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
1079923
25214