Convert Mongo.Collection to class and remove underscore on client.

This commit is contained in:
Ben Newman
2017-11-13 13:40:49 -05:00
parent ef76652a89
commit 6fcf190bb4
4 changed files with 515 additions and 487 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,9 @@
Tinytest.add(
'collection - call Mongo.Collection without new',
function (test) {
test.throws(
function () {
Mongo.Collection(null);
},
/use "new" to construct a Mongo\.Collection/
);
test.throws(function () {
Mongo.Collection(null);
});
}
);

View File

@@ -1,29 +1,30 @@
LocalCollectionDriver = function () {
var self = this;
self.noConnCollections = {};
};
// singleton
export const LocalCollectionDriver = new (class LocalCollectionDriver {
constructor() {
this.noConnCollections = Object.create(null);
}
var ensureCollection = function (name, collections) {
if (!(name in collections))
collections[name] = new LocalCollection(name);
return collections[name];
};
_.extend(LocalCollectionDriver.prototype, {
open: function (name, conn) {
var self = this;
if (!name)
open(name, conn) {
if (! name) {
return new LocalCollection;
if (! conn) {
return ensureCollection(name, self.noConnCollections);
}
if (! conn._mongo_livedata_collections)
conn._mongo_livedata_collections = {};
if (! conn) {
return ensureCollection(name, this.noConnCollections);
}
if (! conn._mongo_livedata_collections) {
conn._mongo_livedata_collections = Object.create(null);
}
// XXX is there a way to keep track of a connection's collections without
// dangling it off the connection object?
return ensureCollection(name, conn._mongo_livedata_collections);
}
});
// singleton
LocalCollectionDriver = new LocalCollectionDriver;
function ensureCollection(name, collections) {
return (name in collections)
? collections[name]
: collections[name] = new LocalCollection(name);
}

View File

@@ -27,7 +27,6 @@ Package.onUse(function (api) {
api.use([
'random',
'ejson',
'underscore',
'minimongo',
'ddp',
'tracker',
@@ -38,6 +37,8 @@ Package.onUse(function (api) {
'mongo-dev-server',
]);
api.use('underscore', 'server');
// Binary Heap data structure is used to optimize oplog observe driver
// performance.
api.use('binary-heap', 'server');