1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const Base = require('./Base');
|
7 |
|
8 | module.exports = class Component extends Base {
|
9 |
|
10 | static getExtendedClassProperties () {
|
11 | return ['BEHAVIORS'];
|
12 | }
|
13 |
|
14 | static getConstants () {
|
15 | return {
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | };
|
21 | }
|
22 |
|
23 | constructor (config) {
|
24 | super({
|
25 |
|
26 |
|
27 | ...config
|
28 | });
|
29 | this.events = ClassHelper.spawn(this.eventManager || EventManager, {
|
30 | owner: this
|
31 | });
|
32 | this.behaviors = ClassHelper.spawn(this.behaviorManager || BehaviorManager, {
|
33 | owner: this,
|
34 | autoAttachedMap: this.BEHAVIORS
|
35 | });
|
36 | }
|
37 |
|
38 | once () {
|
39 | this.ensureBehaviors();
|
40 | this.events.once(...arguments);
|
41 | }
|
42 |
|
43 | on () {
|
44 | this.ensureBehaviors();
|
45 | this.events.on(...arguments);
|
46 | }
|
47 |
|
48 | off () {
|
49 | this.ensureBehaviors();
|
50 | this.events.off(...arguments);
|
51 | }
|
52 |
|
53 | trigger () {
|
54 | this.ensureBehaviors();
|
55 | return this.events.trigger(...arguments);
|
56 | }
|
57 |
|
58 | getBehavior (name) {
|
59 | return this.behaviors.get(name);
|
60 | }
|
61 |
|
62 | attachBehavior () {
|
63 | return this.behaviors.attach(...arguments);
|
64 | }
|
65 |
|
66 | attachBehaviorOnce () {
|
67 | return this.behaviors.attachOnce(...arguments);
|
68 | }
|
69 |
|
70 | detachBehavior (name) {
|
71 | return this.behaviors.detach(name);
|
72 | }
|
73 |
|
74 | getAllBehaviors () {
|
75 | return this.behaviors.getAll();
|
76 | }
|
77 |
|
78 | attachAllBehaviors (data) {
|
79 | this.behaviors.attachAll(data);
|
80 | }
|
81 |
|
82 | detachAllBehaviors () {
|
83 | this.behaviors.detachAll();
|
84 | }
|
85 |
|
86 | ensureBehaviors () {
|
87 | this.behaviors.ensure();
|
88 | }
|
89 |
|
90 | translate () {
|
91 | return this.module.translate(...arguments);
|
92 | }
|
93 |
|
94 | log () {
|
95 | CommonHelper.log(this.module, this.constructor.name, ...arguments);
|
96 | }
|
97 | };
|
98 |
|
99 | const ClassHelper = require('../helper/ClassHelper');
|
100 | const CommonHelper = require('../helper/CommonHelper');
|
101 | const EventManager = require('./EventManager');
|
102 | const BehaviorManager = require('./BehaviorManager'); |
\ | No newline at end of file |