UNPKG

1.49 kBJavaScriptView Raw
1'use strict';
2
3var UUID = require('uuid');
4var _isInheritsFrom = require('./helper/isInheritsFrom');
5var isIFNodeItem = require('./helper/isIFNodeItem');
6var isIFNodeItemInstance = require('./helper/isIFNodeItemInstance');
7var toArray = require('./helper/toArray');
8var PLUGIN_TYPES = require('./PLUGIN_TYPES');
9
10/**
11 *
12 * @typedef {Object} ComponentOptions
13 *
14 * @property {string} [name]
15 * @property {Array.<string>} [alias=[]]
16 * @property {Object} [config={}]
17 */
18
19/**
20 *
21 * @class Component
22 *
23 * @param {ComponentOptions} [options={}]
24 */
25function 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
34Object.defineProperties(Component, {
35 __IFNODE_ITEM: {
36 value: PLUGIN_TYPES.COMPONENT
37 },
38
39 isInstanceOf: {
40 /**
41 *
42 * @param {*} object
43 * @returns {boolean}
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 * @param {*} Base
54 * @returns {boolean}
55 */
56 value: function isInheritsFrom(Base) {
57 return _isInheritsFrom(Base, this) || isIFNodeItem(Base, this.__IFNODE_ITEM);
58 }
59 }
60});
61
62module.exports = Component;