Permalink
Browse files

Make transforms on collections always nonreactive

  • Loading branch information...
1 parent a3287a6 commit 575320b9291fc7624243a4ac9241702ec058574e @sixolet sixolet committed with glasser Mar 12, 2013
View
@@ -274,6 +274,23 @@
}
},
+ // Wrap `f` so that it is always run nonreactively.
+ _makeNonreactive: function (f) {
+ if (f.$isNonreactive) // avoid multiple layers of wrapping.
+ return f;
+ var nonreactiveVersion = function (/*arguments*/) {
+ var self = this;
+ var args = _.toArray(arguments);
+ var ret;
+ Deps.nonreactive(function () {
+ ret = f.apply(self, args);
+ });
+ return ret;
+ };
+ nonreactiveVersion.$isNonreactive = true;
+ return nonreactiveVersion;
+ },
+
onInvalidate: function (f) {
if (! Deps.active)
throw new Error("Deps.onInvalidate requires a currentComputation");
@@ -97,7 +97,10 @@ LocalCollection.Cursor = function (collection, selector, options) {
}
self.skip = options.skip;
self.limit = options.limit;
- self._transform = options.transform;
+ if (options.transform && typeof Deps !== "undefined")
+ self._transform = Deps._makeNonreactive(options.transform);
+ else
+ self._transform = options.transform;
// db_objects is a list of the objects that match the cursor. (It's always a
// list, never an object: LocalCollection.Cursor is always ordered.)
@@ -34,7 +34,10 @@ Meteor.Collection = function (name, options) {
break;
}
- self._transform = options.transform;
+ if (options.transform)
+ self._transform = Deps._makeNonreactive(options.transform);
+ else
+ self._transform = null;
if (!name && (name !== null)) {
Meteor._debug("Warning: creating anonymous collection. It will not be " +
@@ -417,7 +420,7 @@ Meteor.Collection.ObjectID = LocalCollection._ObjectID;
if (self._transform)
options[name].transform = self._transform;
if (options.transform)
- options[name].transform = options.transform;
+ options[name].transform = Deps._makeNonreactive(options.transform);
self._validators[name][allowOrDeny].push(options[name]);
}
});
@@ -467,7 +467,10 @@ _Mongo.prototype._createSynchronousCursor = function (cursorDescription,
var SynchronousCursor = function (dbCursor, transform) {
var self = this;
- self._transform = transform;
+ if (transform)
+ self._transform = Deps._makeNonreactive(transform);
+ else
+ self._transform = transform;
self._dbCursor = dbCursor;
// Need to specify that the callback is the first argument to nextObject,
// since otherwise when we try to call it with no args the driver will

1 comment on commit 575320b

@svasva
svasva commented on 575320b Mar 13, 2013

What is the point of making transforms non-reactive? Just wondering.

Please sign in to comment.