mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Allow Meteor.Collections with name but no connection.
Also differentiate LocalCollections based on connection, not just name.
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
// LiveResultsSet: the return value of a live query.
|
||||
|
||||
// @export LocalCollection
|
||||
LocalCollection = function () {
|
||||
LocalCollection = function (name) {
|
||||
this.name = name;
|
||||
this.docs = {}; // _id -> document (also containing id)
|
||||
|
||||
this._observeQueue = new Meteor._SynchronousQueue();
|
||||
@@ -194,6 +195,12 @@ LocalCollection.Cursor.prototype.count = function () {
|
||||
return self.db_objects.length;
|
||||
};
|
||||
|
||||
LocalCollection.Cursor.prototype._publishCursor = function (sub) {
|
||||
var self = this;
|
||||
var collection = self.collection.name;
|
||||
return Meteor.Collection._publishCursor(self, sub, collection);
|
||||
};
|
||||
|
||||
LocalCollection._isOrderedChanges = function (callbacks) {
|
||||
if (callbacks.added && callbacks.addedBefore)
|
||||
throw new Error("Please specify only one of added() and addedBefore()");
|
||||
|
||||
@@ -49,10 +49,15 @@ Meteor.Collection = function (name, options) {
|
||||
"the collection name to turn off this warning.)");
|
||||
}
|
||||
|
||||
// note: nameless collections never have a connection
|
||||
self._connection = name && (options.connection ||
|
||||
(Meteor.isClient ?
|
||||
Meteor.default_connection : Meteor.default_server));
|
||||
if (! name || options.connection === null)
|
||||
// note: nameless collections never have a connection
|
||||
self._connection = null;
|
||||
else if (options.connection)
|
||||
self._connection = options.connection;
|
||||
else if (Meteor.isClient)
|
||||
self._connection = Meteor.default_connection;
|
||||
else
|
||||
self._connection = Meteor.default_server;
|
||||
|
||||
if (!options._driver) {
|
||||
if (name && self._connection === Meteor.default_server &&
|
||||
@@ -62,10 +67,10 @@ Meteor.Collection = function (name, options) {
|
||||
options._driver = Meteor._LocalCollectionDriver;
|
||||
}
|
||||
|
||||
self._collection = options._driver.open(name);
|
||||
self._collection = options._driver.open(name, self._connection);
|
||||
self._name = name;
|
||||
|
||||
if (name && self._connection.registerStore) {
|
||||
if (self._connection && 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.
|
||||
|
||||
@@ -1,17 +1,28 @@
|
||||
// XXX namespacing
|
||||
Meteor._LocalCollectionDriver = function () {
|
||||
var self = this;
|
||||
self.collections = {};
|
||||
self.noConnCollections = {};
|
||||
};
|
||||
|
||||
var ensureCollection = function (name, collections) {
|
||||
if (!(name in collections))
|
||||
collections[name] = new LocalCollection(name);
|
||||
return collections[name];
|
||||
};
|
||||
|
||||
_.extend(Meteor._LocalCollectionDriver.prototype, {
|
||||
open: function (name) {
|
||||
open: function (name, conn) {
|
||||
var self = this;
|
||||
if (!name)
|
||||
return new LocalCollection;
|
||||
if (!(name in self.collections))
|
||||
self.collections[name] = new LocalCollection;
|
||||
return self.collections[name];
|
||||
if (! conn) {
|
||||
return ensureCollection(name, self.noConnCollections);
|
||||
}
|
||||
if (! conn.collections)
|
||||
conn.collections = {};
|
||||
// XXX is there a way to keep track of a connection's collections without
|
||||
// dangling it off the connection object?
|
||||
return ensureCollection(name, conn.collections);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user