This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
forked from Meteor-Community-Packages/meteor-tabular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
51 lines (37 loc) · 1.36 KB
/
common.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* global Tabular:true, tablesByName:true, Mongo, _, Meteor */
Tabular = {}; //exported
tablesByName = {};
Tabular.Table = function (options) {
var self = this;
if (!options) {
throw new Error('Tabular.Table options argument is required');
}
if (!options.name) {
throw new Error('Tabular.Table options must specify name');
}
self.name = options.name;
if (!(options.collection instanceof Mongo.Collection)) {
throw new Error('Tabular.Table options must specify collection');
}
self.collection = options.collection;
self.pub = options.pub || 'tabular_genericPub';
// By default we use core `Meteor.subscribe`, but you can pass
// a subscription manager like `sub: new SubsManager({cacheLimit: 20, expireIn: 3})`
self.sub = options.sub || Meteor;
self.onUnload = options.onUnload;
self.allow = options.allow;
self.allowFields = options.allowFields;
if (_.isArray(options.extraFields)) {
var fields = {};
_.each(options.extraFields, function (fieldName) {
fields[fieldName] = 1;
});
self.extraFields = fields;
}
self.selector = options.selector;
if (!options.columns) {
throw new Error('Tabular.Table options must specify columns');
}
self.options = _.omit(options, 'collection', 'pub', 'sub', 'onUnload', 'allow', 'allowFields', 'extraFields', 'name', 'selector');
tablesByName[self.name] = self;
};