From 4e552ec514c28c6334603efa769a696b605b31f3 Mon Sep 17 00:00:00 2001 From: Nick Martin Date: Thu, 16 Feb 2012 16:24:58 -0800 Subject: [PATCH 1/3] Don't send empty objects to the client. --- packages/livedata/livedata_server.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/livedata/livedata_server.js b/packages/livedata/livedata_server.js index 17f08da420..1f09974019 100644 --- a/packages/livedata/livedata_server.js +++ b/packages/livedata/livedata_server.js @@ -107,12 +107,17 @@ _.extend(Meteor._LivedataServer.prototype, { var msg = {msg: 'data', collection: collection_name, id: id}; if (!old_obj) { + // New object. Send an insert down to the client. var obj_to_send = _.extend({}, new_obj); delete obj_to_send._id; - msg.set = obj_to_send; - socket.send(JSON.stringify(msg)); + if (_.keys(obj_to_send).length) { + msg.set = obj_to_send; + socket.send(JSON.stringify(msg)); + } } else { + // Old object. Check for updates and send changes attributes + // to the client. var set = {}; var unset = []; From c309647c0c240e07598d95453279565f063037b8 Mon Sep 17 00:00:00 2001 From: Nick Martin Date: Thu, 16 Feb 2012 16:25:12 -0800 Subject: [PATCH 2/3] Warn on empty object insert. --- packages/livedata/livedata_client.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/livedata/livedata_client.js b/packages/livedata/livedata_client.js index e8c2aa6540..a0b2f88201 100644 --- a/packages/livedata/livedata_client.js +++ b/packages/livedata/livedata_client.js @@ -355,7 +355,10 @@ _.extend(Meteor._Collection.prototype, { // Generate an id for the object. // XXX mutates the object passed in. that is not cool. if (obj._id) - Meteor._debug("WARNING: trying to insert object w/ _id set"); + Meteor._debug("WARNING: trying to insert object w/ _id set. _id ignored."); + if (_.keys(obj).length === 0) + Meteor._debug("WARNING: inserting empty object."); + var _id = Collection.uuid(); obj._id = _id; From 1ce3f3b8125ad35183f5972fd3c88a2ef70cf156 Mon Sep 17 00:00:00 2001 From: Nick Martin Date: Thu, 16 Feb 2012 17:50:54 -0800 Subject: [PATCH 3/3] Add note in docs re empty objects. --- docs/client/api.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/client/api.html b/docs/client/api.html index f511f17590..a242eed407 100644 --- a/docs/client/api.html +++ b/docs/client/api.html @@ -84,6 +84,15 @@ Meteor.publish("user-posts", { }); +

Publish acts on individual attributes of objects. If an object has no +attributes except _id, it will not be published to the +client. Generally, empty object are not very useful so this is not a +problem. If you need to create and track an object and assign it +properties later, create it with a simple property +eg: collection.insert({exists: true}); +

+ +