Skip to content

Commit

Permalink
Clone DDP data as it goes into the merge box
Browse files Browse the repository at this point in the history
Fixes #1750.
  • Loading branch information
glasser committed Feb 17, 2014
1 parent 3eb4a13 commit 764b41a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions History.md
Expand Up @@ -152,6 +152,8 @@
* User-supplied connect handlers now see the URL's full path, even if
ROOT_URL contains a non-empty path.

* Don't cache direct references to the fields arguments to the subscription
`added` and `changed` methods. #1750


## v0.7.0.1
Expand Down
4 changes: 4 additions & 0 deletions packages/livedata/livedata_server.js
Expand Up @@ -68,6 +68,10 @@ _.extend(SessionDocumentView.prototype, {
// Publish API ignores _id if present in fields
if (key === "_id")
return;

// Don't share state with the data passed in by the user.
value = EJSON.clone(value);

if (!_.has(self.dataByKey, key)) {
self.dataByKey[key] = [{subscriptionHandle: subscriptionHandle,
value: value}];
Expand Down
25 changes: 25 additions & 0 deletions packages/livedata/livedata_tests.js
Expand Up @@ -691,6 +691,31 @@ if (Meteor.isServer) {
]);
})();

if (Meteor.isServer) {
Meteor.publish("publisherCloning", function () {
var self = this;
var fields = {x: {y: 42}};
self.added("publisherCloning", "a", fields);
fields.x.y = 43;
self.changed("publisherCloning", "a", fields);
self.ready();
});
} else {
var PublisherCloningCollection = new Meteor.Collection("publisherCloning");
testAsyncMulti("livedata - publish callbacks clone", [
function (test, expect) {
Meteor.subscribe("publisherCloning", {normal: 1}, {
onReady: expect(function () {
test.equal(PublisherCloningCollection.findOne(), {
_id: "a",
x: {y: 43}});
}),
onError: failure()
});
}
]);
}


// XXX some things to test in greater detail:
// staying in simulation mode
Expand Down

0 comments on commit 764b41a

Please sign in to comment.