Merge branch 'refs/heads/empty-objects'

This commit is contained in:
Nick Martin
2012-02-16 18:45:15 -08:00
3 changed files with 20 additions and 3 deletions

View File

@@ -84,6 +84,15 @@ Meteor.publish("user-posts", {
});
</pre>
<p>Publish acts on individual attributes of objects. If an object has no
attributes except <code>_id</code>, 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: <code>collection.insert({exists: true});</code>
</p>
<!------------------------------------------------------------------->
<!-- Meteor.subscribe -------------------------------------------------->

View File

@@ -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;

View File

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