mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
In the client, now all internal "abstract ddp" uses fieldName: undefined
Instead of a cleared list. The wire format still has a cleared list.
This commit is contained in:
committed by
David Glasser
parent
f2209076e1
commit
48203263e3
@@ -4,6 +4,20 @@ if (Meteor.isServer) {
|
||||
var Future = __meteor_bootstrap__.require(path.join('fibers', 'future'));
|
||||
}
|
||||
|
||||
var parseDDP = function (stringMessage) {
|
||||
var msg = JSON.parse(stringMessage);
|
||||
//massage msg to get it into "abstract ddp" rather than "wire ddp" format.
|
||||
if (_.has(msg, 'cleared')) {
|
||||
if (!_.has(msg, 'fields'))
|
||||
msg.fields = {};
|
||||
_.each(msg.cleared, function (clearKey) {
|
||||
msg.fields[clearKey] = undefined;
|
||||
});
|
||||
delete msg.cleared;
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
// @param url {String|Object} URL to Meteor app,
|
||||
// or an object as a test hook (see code)
|
||||
// Options:
|
||||
@@ -174,7 +188,7 @@ Meteor._LivedataConnection = function (url, options) {
|
||||
|
||||
self._stream.on('message', function (raw_msg) {
|
||||
try {
|
||||
var msg = JSON.parse(raw_msg);
|
||||
var msg = parseDDP(raw_msg);
|
||||
} catch (err) {
|
||||
Meteor._debug("discarding message with invalid JSON", raw_msg);
|
||||
return;
|
||||
@@ -992,12 +1006,7 @@ _.extend(Meteor._LivedataConnection.prototype, {
|
||||
throw new Error("It doesn't make sense to be changing something we don't think exists: "
|
||||
+ msg.id);
|
||||
}
|
||||
_.each(msg.fields, function (value, key) {
|
||||
serverDoc.document[key] = value;
|
||||
});
|
||||
_.each(msg.cleared, function (clearedKey) {
|
||||
delete serverDoc.document[clearedKey];
|
||||
});
|
||||
LocalCollection._applyChanges(serverDoc.document, msg.fields);
|
||||
} else {
|
||||
self._pushUpdate(updates, msg.collection, msg);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,14 @@ LocalCollection = function () {
|
||||
this.paused = false;
|
||||
};
|
||||
|
||||
LocalCollection._applyChanges = function (doc, changeFields) {
|
||||
_.each(changeFields, function (value, key) {
|
||||
if (value === undefined)
|
||||
delete doc[key];
|
||||
else
|
||||
doc[key] = value;
|
||||
});
|
||||
};
|
||||
// options may include sort, skip, limit, reactive
|
||||
// sort may be any of these forms:
|
||||
// {a: 1, b: -1}
|
||||
|
||||
Reference in New Issue
Block a user