Merge pull request #749 from CartoDB/dataview-factory-refactor
Dataview factory refactor
This commit is contained in:
commit
19e2515a8e
@ -1,18 +1,20 @@
|
|||||||
var dataviews = require('./');
|
const dataviews = require('./');
|
||||||
|
|
||||||
var DataviewFactory = {
|
module.exports = class DataviewFactory {
|
||||||
dataviews: Object.keys(dataviews).reduce(function(allDataviews, dataviewClassName) {
|
static get dataviews() {
|
||||||
allDataviews[dataviewClassName.toLowerCase()] = dataviews[dataviewClassName];
|
return Object.keys(dataviews).reduce((allDataviews, dataviewClassName) => {
|
||||||
return allDataviews;
|
allDataviews[dataviewClassName.toLowerCase()] = dataviews[dataviewClassName];
|
||||||
}, {}),
|
return allDataviews;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
static getDataview (query, dataviewDefinition) {
|
||||||
|
const { type, options, sql } = dataviewDefinition;
|
||||||
|
|
||||||
getDataview: function(query, dataviewDefinition) {
|
|
||||||
var type = dataviewDefinition.type;
|
|
||||||
if (!this.dataviews[type]) {
|
if (!this.dataviews[type]) {
|
||||||
throw new Error('Invalid dataview type: "' + type + '"');
|
throw new Error('Invalid dataview type: "' + type + '"');
|
||||||
}
|
}
|
||||||
return new this.dataviews[type](query, dataviewDefinition.options, dataviewDefinition.sql);
|
|
||||||
|
return new this.dataviews[type](query, options, sql);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = DataviewFactory;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user