1 | 'use strict';
|
2 |
|
3 | var UUID = require('uuid');
|
4 | var _isInheritsFrom = require('./helper/isInheritsFrom');
|
5 | var isIFNodeItem = require('./helper/isIFNodeItem');
|
6 | var isIFNodeItemInstance = require('./helper/isIFNodeItemInstance');
|
7 | var toArray = require('./helper/toArray');
|
8 | var PLUGIN_TYPES = require('./PLUGIN_TYPES');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | function Component(options) {
|
26 | options = options || {};
|
27 |
|
28 | this.id = UUID.v4();
|
29 | this.name = options.name || this.constructor.name;
|
30 | this.config = options.config || {};
|
31 | this.alias = toArray(options.alias);
|
32 | }
|
33 |
|
34 | Object.defineProperties(Component, {
|
35 | __IFNODE_ITEM: {
|
36 | value: PLUGIN_TYPES.COMPONENT
|
37 | },
|
38 |
|
39 | isInstanceOf: {
|
40 | |
41 |
|
42 |
|
43 |
|
44 |
|
45 | value: function isInstanceOf(object) {
|
46 | return !!object && (object instanceof this || isIFNodeItemInstance(object, this.__IFNODE_ITEM));
|
47 | }
|
48 | },
|
49 |
|
50 | isInheritsFrom: {
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 | value: function isInheritsFrom(Base) {
|
57 | return _isInheritsFrom(Base, this) || isIFNodeItem(Base, this.__IFNODE_ITEM);
|
58 | }
|
59 | }
|
60 | });
|
61 |
|
62 | module.exports = Component;
|