diff --git a/History.md b/History.md index 8ef12e7cf9c..238574bdc26 100644 --- a/History.md +++ b/History.md @@ -1,6 +1,9 @@ ## vNEXT +* The `manager` option to the `Meteor.Collection` constructor is now called + `connection`. The old name still works for now. #987 + * Files in the 'client/compatibility/' subdirectory of a Meteor app do not get wrapped in a new variable scope. diff --git a/docs/client/api.js b/docs/client/api.js index 7f6bea72c25..0829aed171b 100644 --- a/docs/client/api.js +++ b/docs/client/api.js @@ -472,9 +472,9 @@ Template.api.meteor_collection = { descr: "The name of the collection. If null, creates an unmanaged (unsynchronized) local collection."} ], options: [ - {name: "manager", + {name: "connection", type: "Object", - descr: "The Meteor connection that will manage this collection, defaults to `Meteor` if null. Unmanaged (`name` is null) collections cannot specify a manager." + descr: "The Meteor connection that will manage this collection, defaults to `Meteor` if null. Unmanaged (`name` is null) collections cannot specify a connection." }, {name: "idGeneration", type: "String", diff --git a/packages/livedata/livedata_connection_tests.js b/packages/livedata/livedata_connection_tests.js index 39dc5e66d46..ef79891bd24 100644 --- a/packages/livedata/livedata_connection_tests.js +++ b/packages/livedata/livedata_connection_tests.js @@ -295,7 +295,7 @@ if (Meteor.isClient) { startAndConnect(test, stream); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); // setup method conn.methods({do_something: function (x) { @@ -438,7 +438,7 @@ if (Meteor.isClient) { startAndConnect(test, stream); var coll_name = Random.id(); - var coll = new Meteor.Collection(coll_name, {manager: conn}); + var coll = new Meteor.Collection(coll_name, {connection: conn}); // setup methods conn.methods({ @@ -522,7 +522,7 @@ Tinytest.add("livedata stub - reconnect", function (test) { startAndConnect(test, stream); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); var o = observeCursor(test, coll.find()); @@ -650,7 +650,7 @@ if (Meteor.isClient) { startAndConnect(test, stream); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); var o = observeCursor(test, coll.find()); conn.methods({writeSomething: function () { @@ -823,7 +823,7 @@ Tinytest.add("livedata stub - reconnect method which only got data", function (t startAndConnect(test, stream); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); var o = observeCursor(test, coll.find()); // Call a method. We'll get the data-done message but not the result before @@ -909,7 +909,7 @@ if (Meteor.isClient) { startAndConnect(test, stream); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); var o = observeCursor(test, coll.find()); conn.methods({ @@ -996,7 +996,7 @@ if (Meteor.isClient) { startAndConnect(test, stream); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); conn.methods({ insertSomething: function () { @@ -1138,7 +1138,7 @@ Tinytest.add("livedata connection - two wait methods", function (test) { startAndConnect(test, stream); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); // setup method conn.methods({do_something: function (x) {}}); @@ -1526,7 +1526,7 @@ if (Meteor.isClient) { var conn = newConnection(stream); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); // Start and send "connect", but DON'T get 'connected' quite yet. stream.reset(); // initial connection start. diff --git a/packages/livedata/livedata_tests.js b/packages/livedata/livedata_tests.js index 88bc2c94d8c..ec754d6a234 100644 --- a/packages/livedata/livedata_tests.js +++ b/packages/livedata/livedata_tests.js @@ -508,7 +508,7 @@ if (Meteor.isClient) { var conn = new Meteor._LivedataConnection('/', {reloadWithOutstanding: true}); var collName = Random.id(); - var coll = new Meteor.Collection(collName, {manager: conn}); + var coll = new Meteor.Collection(collName, {connection: conn}); var errorFromRerun; var gotErrorFromStopper = false; return [ diff --git a/packages/madewith/madewith.js b/packages/madewith/madewith.js index 37055061c2b..297d8d9a292 100644 --- a/packages/madewith/madewith.js +++ b/packages/madewith/madewith.js @@ -8,7 +8,7 @@ var server = Meteor.connect("madewith.meteor.com"); var sub = server.subscribe("myApp", hostname); // minimongo collection to hold my singleton app record. -var apps = new Meteor.Collection('madewith_apps', {manager: server}); +var apps = new Meteor.Collection('madewith_apps', {connection: server}); server.methods({ vote: function (hostname) { diff --git a/packages/mongo-livedata/collection.js b/packages/mongo-livedata/collection.js index d61d55f63af..d67ea71158f 100644 --- a/packages/mongo-livedata/collection.js +++ b/packages/mongo-livedata/collection.js @@ -1,4 +1,4 @@ -// manager, if given, is a LivedataClient or LivedataServer +// connection, if given, is a LivedataClient or LivedataServer // XXX presently there is no way to destroy/clean up a Collection Meteor.Collection = function (name, options) { @@ -7,13 +7,17 @@ Meteor.Collection = function (name, options) { throw new Error('use "new" to construct a Meteor.Collection'); if (options && options.methods) { // Backwards compatibility hack with original signature (which passed - // "manager" directly instead of in options. (Managers must have a "methods" + // "connection" directly instead of in options. (Connections must have a "methods" // method.) // XXX remove before 1.0 - options = {manager: options}; + options = {connection: options}; + } + // Backwards compatibility: "connection" used to be called "manager". + if (options && options.manager && !options.connection) { + options.connection = options.manager; } options = _.extend({ - manager: undefined, + connection: undefined, idGeneration: 'STRING', transform: null, _driver: undefined, @@ -45,13 +49,13 @@ Meteor.Collection = function (name, options) { "the collection name to turn off this warning.)"); } - // note: nameless collections never have a manager - self._manager = name && (options.manager || + // note: nameless collections never have a connection + self._connection = name && (options.connection || (Meteor.isClient ? Meteor.default_connection : Meteor.default_server)); if (!options._driver) { - if (name && self._manager === Meteor.default_server && + if (name && self._connection === Meteor.default_server && Meteor._RemoteCollectionDriver) options._driver = Meteor._RemoteCollectionDriver; else @@ -61,11 +65,11 @@ Meteor.Collection = function (name, options) { self._collection = options._driver.open(name); self._name = name; - if (name && self._manager.registerStore) { + if (name && self._connection.registerStore) { // OK, we're going to be a slave, replicating some remote // database, except possibly with some temporary divergence while // we have unacknowledged RPC's. - var ok = self._manager.registerStore(name, { + var ok = self._connection.registerStore(name, { // Called at the beginning of a batch of updates. batchSize is the number // of update calls to expect. // @@ -166,10 +170,10 @@ Meteor.Collection = function (name, options) { // autopublish if (!options._preventAutopublish && - self._manager && self._manager.onAutopublish) - self._manager.onAutopublish(function () { + self._connection && self._connection.onAutopublish) + self._connection.onAutopublish(function () { var handler = function () { return self.find(); }; - self._manager.publish(null, handler, {is_auto: true}); + self._connection.publish(null, handler, {is_auto: true}); }); }; @@ -324,7 +328,7 @@ _.each(["insert", "update", "remove"], function (name) { args[0] = Meteor.Collection._rewriteSelector(args[0]); } - if (self._manager && self._manager !== Meteor.default_server) { + if (self._connection && self._connection !== Meteor.default_server) { // just remote to another endpoint, propagate return value or // exception. @@ -341,12 +345,12 @@ _.each(["insert", "update", "remove"], function (name) { // asynchronous: on success, callback should return ret // (document ID for insert, undefined for update and // remove), not the method's result. - self._manager.apply(self._prefix + name, args, function (error, result) { + self._connection.apply(self._prefix + name, args, function (error, result) { callback(error, !error && ret); }); } else { // synchronous: propagate exception - self._manager.apply(self._prefix + name, args); + self._connection.apply(self._prefix + name, args); } } else { @@ -362,7 +366,7 @@ _.each(["insert", "update", "remove"], function (name) { throw e; } - // on success, return *ret*, not the manager's return value. + // on success, return *ret*, not the connection's return value. callback && callback(null, ret); } @@ -497,7 +501,7 @@ Meteor.Collection.prototype._defineMutationMethods = function() { self._prefix = '/' + self._name + '/'; // mutation methods - if (self._manager) { + if (self._connection) { var m = {}; _.each(['insert', 'update', 'remove'], function (method) { @@ -553,8 +557,8 @@ Meteor.Collection.prototype._defineMutationMethods = function() { // Minimongo on the server gets no stubs; instead, by default // it wait()s until its result is ready, yielding. // This matches the behavior of macromongo on the server better. - if (Meteor.isClient || self._manager === Meteor.default_server) - self._manager.methods(m); + if (Meteor.isClient || self._connection === Meteor.default_server) + self._connection.methods(m); } }; diff --git a/packages/mongo-livedata/mongo_livedata_tests.js b/packages/mongo-livedata/mongo_livedata_tests.js index ea9c7d3031b..84efed85f1c 100644 --- a/packages/mongo-livedata/mongo_livedata_tests.js +++ b/packages/mongo-livedata/mongo_livedata_tests.js @@ -880,7 +880,7 @@ if (Meteor.isServer) { var self = this; if (self.conn.status().connected) { self.miniC = new Meteor.Collection("ServerMinimongo_" + self.id, { - manager: self.conn + connection: self.conn }); var exp = expect(function (err) { test.isFalse(err); @@ -933,7 +933,7 @@ if (Meteor.isServer) { var self = this; if (self.conn.status().connected) { self.miniC = new Meteor.Collection("ServerMinimongoObserve_" + self.id, { - manager: self.conn + connection: self.conn }); var exp = expect(function (err) { test.isFalse(err);