1 | ;
|
2 |
|
3 | const _ = require('lodash');
|
4 |
|
5 | class 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 |
|
21 | module.exports = Factory;
|