UNPKG

345 BJavaScriptView Raw
1'use strict';
2
3const _ = require('lodash');
4
5class Factory {
6 get types() {
7 return {};
8 }
9
10 create(name, options, context) {
11 const constructor = _.get(this.types, name);
12
13 if (!constructor) {
14 throw new Error(`Factory can't find ${name}`);
15 }
16
17 return new constructor(options, context);
18 }
19}
20
21module.exports = Factory;