Use observeChanges based observe for ordered observes on the server too

This commit is contained in:
Naomi Seyfer
2013-01-31 10:22:12 -08:00
parent d8b137df76
commit 42a4d8537b
2 changed files with 10 additions and 12 deletions

View File

@@ -890,7 +890,7 @@ LocalCollection._observeUnordered = function (cursor, callbacks) {
var doc = EJSON.clone(fields);
doc._id = id;
docs[strId] = doc;
suppressed || callbacks.added(doc);
suppressed || callbacks.added && callbacks.added(doc);
},
changed: function (id, fields) {
var strId = LocalCollection._idStringify(id);
@@ -898,13 +898,13 @@ LocalCollection._observeUnordered = function (cursor, callbacks) {
var oldDoc = EJSON.clone(doc);
// writes through to the doc set
LocalCollection._applyChanges(doc, fields);
suppressed || callbacks.changed(doc, oldDoc);
suppressed || callbacks.changed && callbacks.changed(doc, oldDoc);
},
removed: function (id) {
var strId = LocalCollection._idStringify(id);
var doc = docs[strId];
delete docs[strId];
suppressed || callbacks.removed(doc);
suppressed || callbacks.removed && callbacks.removed(doc);
}
});
suppressed = false;
@@ -921,7 +921,7 @@ LocalCollection._observeOrdered = function (cursor, callbacks) {
doc._id = id;
docs.putBefore(strId, doc, before ? LocalCollection._idStringify(before) : null);
var index = docs.indexOf(strId);
suppressed || callbacks.added(EJSON.clone(doc), index);
suppressed || callbacks.added && callbacks.added(EJSON.clone(doc), index);
},
changed: function (id, fields) {
var strId = LocalCollection._idStringify(id);
@@ -930,7 +930,7 @@ LocalCollection._observeOrdered = function (cursor, callbacks) {
var index = docs.indexOf(strId);
// writes through to the doc set
LocalCollection._applyChanges(doc, fields);
suppressed || callbacks.changed(EJSON.clone(doc), index, oldDoc);
suppressed || callbacks.changed && callbacks.changed(EJSON.clone(doc), index, oldDoc);
},
movedBefore: function (id, before) {
var strId = LocalCollection._idStringify(id);
@@ -938,14 +938,14 @@ LocalCollection._observeOrdered = function (cursor, callbacks) {
var from = docs.indexOf(strId);
docs.moveBefore(strId, before ? LocalCollection._idStringify(before) : null);
var to = docs.indexOf(strId);
suppressed || callbacks.moved(EJSON.clone(doc), from, to);
suppressed || callbacks.moved && callbacks.moved(EJSON.clone(doc), from, to);
},
removed: function (id) {
var strId = LocalCollection._idStringify(id);
var doc = docs.get(strId);
var index = docs.indexOf(strId);
docs.remove(strId);
suppressed || callbacks.removed(doc, index);
suppressed || callbacks.removed && callbacks.removed(doc, index);
}
});
suppressed = false;

View File

@@ -364,8 +364,7 @@ Cursor.prototype._publishCursor = function (sub) {
Cursor.prototype.observe = function (callbacks) {
var self = this;
return self._mongo._observe(
self._cursorDescription, true, callbacks);
return LocalCollection._observeOrdered(self, callbacks);
};
Cursor.prototype._observeUnordered = function (callbacks) {
@@ -512,7 +511,7 @@ ObserveHandle.prototype.stop = function () {
_Mongo.prototype._observe = function (cursorDescription, ordered, callbacks, observeChanges) {
var self = this;
var observeKey = JSON.stringify(
_.extend({ordered: ordered}, cursorDescription));
_.extend({ordered: ordered, observeChanges: observeChanges}, cursorDescription));
var liveResultsSet;
var observeHandle;
@@ -761,7 +760,6 @@ _.extend(LiveResultsSet.prototype, {
// with a call to _pollMongo or another call to this function.
_addObserveHandleAndSendInitialAdds: function (handle) {
var self = this;
// Keep track of how many of these tasks are on the queue, so that
// _removeObserveHandle knows if it's safe to GC.
++self._addHandleTasksScheduledButNotPerformed;
@@ -776,7 +774,7 @@ _.extend(LiveResultsSet.prototype, {
--self._addHandleTasksScheduledButNotPerformed;
// Send initial adds.
if (handle._added) {
if (handle._added || handle._addedBefore) {
_.each(self._results, function (doc, i) {
var fields = EJSON.clone(doc);
if (self._observeChanges) {