Skip to content
This repository has been archived by the owner on May 19, 2019. It is now read-only.

Commit

Permalink
added indication in _prepareCursor by options that cursor is observing
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Artemyev committed Jan 7, 2016
1 parent 7584acf commit d3c39f4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/Collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export class Collection extends EventEmitter {
* @param {Object} query
* @return {CursorObservable}
*/
find(query) {
return new _defaultCursorClass(this, query);
find(query, options = {}) {
return new _defaultCursorClass(this, query, options);
}

/**
Expand All @@ -255,8 +255,8 @@ export class Collection extends EventEmitter {
* @param {Object} sortObj
* @return {Promise}
*/
findOne(query, sortObj) {
return this.find(query)
findOne(query, sortObj, options = {}) {
return this.find(query, options)
.sort(sortObj).limit(1)
.aggregate(docs => docs[0]);
}
Expand Down
9 changes: 5 additions & 4 deletions lib/Cursor.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ export const PIPELINE_PROCESSORS = {
* fully customizable response
*/
export class Cursor extends EventEmitter {
constructor(db, query) {
constructor(db, query, options) {
super();
this.db = db;
this.options = options;
this._query = query;
this._pipeline = [];
this._executing = null;
Expand Down Expand Up @@ -274,8 +275,8 @@ export class Cursor extends EventEmitter {
return docs.slice(skip, limit + skip);
}

exec() {
this._executing = this._prepareCursor()
exec(options = {}) {
this._executing = this._prepareCursor(options)
.then(() => this._matchObjects())
.then(docs => {
const clonned = _map(docs, doc => EJSON.clone(doc));
Expand Down Expand Up @@ -309,7 +310,7 @@ export class Cursor extends EventEmitter {
return Promise.resolve(this._executing);
}

_prepareCursor() {
_prepareCursor(options = {}) {
return Promise.resolve();
}

Expand Down
9 changes: 6 additions & 3 deletions lib/CursorObservable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import EJSON from './EJSON';
* after some changes is happen in a database.
*/
export class CursorObservable extends Cursor {
constructor(db, query) {
super(db, query);
constructor(db, query, options) {
super(db, query, options);
this.update = debounce(_bind(this.update, this), 1000 / 15, 10);
this.maybeUpdate = _bind(this.maybeUpdate, this);
}
Expand Down Expand Up @@ -122,7 +122,10 @@ export class CursorObservable extends Cursor {
* @return {Promise}
*/
update(firstRun = false) {
return this.exec().then((result) => {
return this.exec({
observable: true,
firstRun: firstRun,
}).then((result) => {
this._latestResult = result;
this._updateLatestIds();
this._propagateUpdate(firstRun);
Expand Down

0 comments on commit d3c39f4

Please sign in to comment.