UNPKG

947 BJavaScriptView Raw
1/**
2 * @copyright Copyright (c) 2019 Maxim Khorin <maksimovichu@gmail.com>
3 */
4'use strict';
5
6const Base = require('./Base');
7
8module.exports = class ClassMapper extends Base {
9
10 init () {
11 this._data = {};
12 this._parent = this.module.parent && this.module.parent.classMapper;
13 Object.assign(this._data, this.getConfig());
14 }
15
16 getConfig () {
17 return this.module.getConfig('classes');
18 }
19
20 get (key) {
21 return Object.prototype.hasOwnProperty.call(this._data, key)
22 ? this._data[key]
23 : this._parent && this._parent.get(key);
24 }
25
26 getOwn (key) {
27 return Object.prototype.hasOwnProperty.call(this._data, key) ? this._data[key] : null;
28 }
29
30 spawn (key, params) {
31 return ClassHelper.spawn(this.get(key), Object.assign({module: this.module}, params));
32 }
33};
34
35const ClassHelper = require('../helper/ClassHelper');
36