mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
mongo_driver.js modified to use added-changed-removed. Tests do not pass yet
This commit is contained in:
committed by
David Glasser
parent
36fe3033cb
commit
ec8b46033a
@@ -15,6 +15,9 @@ Meteor._SessionDocumentView = function (id) {
|
||||
_.extend(Meteor._SessionDocumentView.prototype, {
|
||||
clearField: function (subscriptionId, key, changeCollector, clearCollector) {
|
||||
var self = this;
|
||||
// Publish API ignores _id if present in fields
|
||||
if (key === "_id")
|
||||
return;
|
||||
var precedenceList = self.dataByKey[key];
|
||||
if (!precedenceList) {
|
||||
throw new Error("Could not find field to clear " + key);
|
||||
@@ -42,6 +45,9 @@ _.extend(Meteor._SessionDocumentView.prototype, {
|
||||
|
||||
changeField: function (subscriptionId, key, value, changeCollector, isAdd) {
|
||||
var self = this;
|
||||
// Publish API ignores _id if present in fields
|
||||
if (key === "_id")
|
||||
return;
|
||||
if (!_.has(self.dataByKey, key)) {
|
||||
self.dataByKey[key] = [{subscriptionId: subscriptionId, value: value}];
|
||||
changeCollector[key] = value;
|
||||
@@ -106,7 +112,8 @@ _.extend(Meteor._SessionCollectionView.prototype, {
|
||||
self.documents[id] = docView;
|
||||
docView.existsIn[subscriptionId] = true;
|
||||
_.each(fields, function (value, key) {
|
||||
docView.dataByKey[key] = [{subscriptionId: subscriptionId, value: value}];
|
||||
if (key !== "_id")
|
||||
docView.dataByKey[key] = [{subscriptionId: subscriptionId, value: value}];
|
||||
});
|
||||
// since nobody else knew about this doc, we can just call added.
|
||||
self.callbacks.added(self.collectionName, id, fields);
|
||||
@@ -700,10 +707,10 @@ _.extend(Meteor._LivedataSubscription.prototype, {
|
||||
this._stopCallbacks.push(callback);
|
||||
},
|
||||
|
||||
added: function (collectionName, document) {
|
||||
added: function (collectionName, id, fields) {
|
||||
var self = this;
|
||||
Meteor._ensure(self._documents, collectionName)[document._id] = true;
|
||||
self._session.added(self._subscriptionId, collectionName, document);
|
||||
Meteor._ensure(self._documents, collectionName)[id] = true;
|
||||
self._session.added(self._subscriptionId, collectionName, id, fields);
|
||||
},
|
||||
|
||||
changed: function (collectionName, id, fields) {
|
||||
|
||||
@@ -296,30 +296,28 @@ Cursor.prototype._publishCursor = function (sub) {
|
||||
|
||||
var observeHandle = self._observeUnordered({
|
||||
added: function (obj) {
|
||||
sub.set(collection, obj._id, obj);
|
||||
sub.flush();
|
||||
sub.added(collection, obj._id, obj);
|
||||
},
|
||||
changed: function (obj, oldObj) {
|
||||
var set = {};
|
||||
var fields = {};
|
||||
_.each(obj, function (v, k) {
|
||||
if (!_.isEqual(v, oldObj[k]))
|
||||
set[k] = v;
|
||||
fields[k] = v;
|
||||
});
|
||||
sub.set(collection, obj._id, set);
|
||||
var deadKeys = _.difference(_.keys(oldObj), _.keys(obj));
|
||||
sub.unset(collection, obj._id, deadKeys);
|
||||
sub.flush();
|
||||
_.each(deadKeys, function (deadKey) {
|
||||
fields[deadKey] = undefined;
|
||||
});
|
||||
sub.changed(collection, obj._id, fields);
|
||||
},
|
||||
removed: function (oldObj) {
|
||||
sub.unset(collection, oldObj._id, _.keys(oldObj));
|
||||
sub.flush();
|
||||
sub.removed(collection, [oldObj._id]);
|
||||
}
|
||||
});
|
||||
|
||||
// _observeUnordered only returns after the initial added callbacks have run.
|
||||
// mark subscription as completed.
|
||||
sub.complete();
|
||||
sub.flush();
|
||||
|
||||
// register stop callback (expects lambda w/ no args).
|
||||
sub.onStop(function () {observeHandle.stop();});
|
||||
|
||||
Reference in New Issue
Block a user