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}); +

+ + 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; 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 = [];