mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Unordered observe based on observeChanges now.
This commit is contained in:
@@ -203,7 +203,7 @@ _.extend(LocalCollection.Cursor.prototype, {
|
||||
},
|
||||
_observeUnordered: function (options) {
|
||||
var self = this;
|
||||
return self._observeInternal(false, options);
|
||||
return LocalCollection._observeUnordered(self, options);
|
||||
},
|
||||
observeChanges: function (callbacks) {
|
||||
var self = this;
|
||||
@@ -872,4 +872,30 @@ LocalCollection._makeChangedFields = function (newDoc, oldDoc) {
|
||||
return fields;
|
||||
};
|
||||
|
||||
LocalCollection._observeUnordered = function (cursor, callbacks) {
|
||||
var docs = {};
|
||||
return cursor.observeChanges({
|
||||
added: function (id, fields) {
|
||||
var strId = LocalCollection._idStringify(id);
|
||||
var doc = EJSON.clone(fields);
|
||||
doc._id = id;
|
||||
docs[strId] = doc;
|
||||
callbacks.added(doc);
|
||||
},
|
||||
changed: function (id, fields) {
|
||||
var strId = LocalCollection._idStringify(id);
|
||||
var doc = docs[strId];
|
||||
var oldDoc = EJSON.clone(docs[strId]);
|
||||
// writes through to the doc set
|
||||
LocalCollection._applyChanges(doc, fields);
|
||||
callbacks.changed(doc, oldDoc);
|
||||
},
|
||||
removed: function (id) {
|
||||
var strId = LocalCollection._idStringify(id);
|
||||
var doc = docs[strId];
|
||||
delete docs[strId];
|
||||
callbacks.removed(doc);
|
||||
}
|
||||
});
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -9,7 +9,6 @@ Package.on_use(function (api, where) {
|
||||
// It would be sort of nice if minimongo didn't depend on
|
||||
// underscore, so we could ship it separately.
|
||||
api.use(['underscore', 'json', 'ejson', 'ordereddict'], where);
|
||||
|
||||
api.add_files([
|
||||
'minimongo.js',
|
||||
'selector.js',
|
||||
|
||||
@@ -354,8 +354,7 @@ Cursor.prototype.observe = function (callbacks) {
|
||||
|
||||
Cursor.prototype._observeUnordered = function (callbacks) {
|
||||
var self = this;
|
||||
return self._mongo._observe(
|
||||
self._cursorDescription, false, callbacks);
|
||||
return LocalCollection._observeUnordered(self, callbacks);
|
||||
};
|
||||
|
||||
Cursor.prototype.observeChanges = function (callbacks) {
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
}
|
||||
if (self._first === null || self._first === elt.next)
|
||||
self._first = elt;
|
||||
self._dict[key] = item;
|
||||
},
|
||||
remove: function (key) {
|
||||
var self = this;
|
||||
|
||||
Reference in New Issue
Block a user