288156a3-6b99-42a5-bfb4-05a42916f834.js
5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"use strict";
cc._RF.push(module, '28815aja5lCpb+0BaQpFvg0', 'CCViewBase');
// script/common/classbase/CCViewBase.ts
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CCPureSubview = exports.CCPureView = exports.CCSubview = exports.CCView = void 0;
const simba_eventkit_1 = require("simba-eventkit");
const ViewBase_1 = require("./ViewBase");
class CCViewBase extends cc.Component {
constructor() {
super(...arguments);
this._emitter = new simba_eventkit_1.Emitter;
this._showed = false;
this._isHidden = false;
this.onShow = this._emitter.createEvent();
this.onHide = this._emitter.createEvent();
}
get isHidden() { return this._isHidden || !this.node.active; }
show() {
if (!this.node.parent || !this.isHidden)
return;
if (this.isHidden) {
this.node.active = true;
this._isHidden = false;
this.node.opacity = 255;
if (this._posX !== undefined)
this.node.x = this._posX;
this.onShow.emit();
}
}
hide() {
if (!this.node.parent || this.isHidden)
return;
if (!this.isHidden) {
this._isHidden = true;
this._posX = this.node.x;
this.node.opacity = 0;
this.node.x = 10000;
this.onHide.emit();
}
}
}
class CCView extends CCViewBase {
constructor() {
super(...arguments);
this._type = "View";
this.onClose = this._emitter.createEvent();
}
open(parent) {
this.node.parent = parent.node;
}
close(destroy) {
if (!this.node.parent)
return;
if (destroy) {
this.node.destroy();
}
else {
this.node.removeFromParent(false);
}
this.onClose.emit(destroy);
}
}
exports.CCView = CCView;
class CCSubview extends CCViewBase {
constructor() {
super();
this._type = "Subview";
ViewBase_1.OnSubviewCreated.emit(this);
}
onLoad() {
this.name = this.node.name;
}
attachParent(parent) {
this.node.parent = parent.node;
}
}
exports.CCSubview = CCSubview;
class PureViewBase {
constructor() {
this._prepareUpdate = false;
this._propBinder = {};
}
setProps(props) {
this._tempProps = props;
if (!this._props) {
this._setProps();
}
else {
if (!this._prepareUpdate) {
this._prepareUpdate = true;
this.scheduleOnce(() => {
this._setProps();
});
}
}
}
_setProps() {
this._prepareUpdate = false;
this._prevProps = this._props;
this._props = Object.assign({}, this._tempProps);
delete this._tempProps;
this.onPropsReceive();
if (!this._prevProps) {
this.onPropsLoad(this._props);
}
else {
let keys = new Set([...Object.keys(this._prevProps), ...Object.keys(this._props)]);
for (let key of keys) {
if (this._props[key] !== this._prevProps[key]) {
this.onPropChange(key);
}
}
}
}
updateProps(props) {
if (!this._props)
throw new Error("setProps first.");
let fullProps = this._tempProps ? Object.assign(Object.assign({}, this._tempProps), props) : Object.assign(Object.assign({}, this._props), props);
this.setProps(fullProps);
}
bindProp(key, target, prop) {
if (!this._propBinder[key])
this._propBinder[key] = [];
this._propBinder[key].push({ target, prop });
}
onPropsReceive() {
}
onPropsLoad(props) {
for (let key in props) {
if (this._propBinder[key]) {
for (const { target, prop } of this._propBinder[key]) {
if (typeof target === "function") {
target(this._props[key]);
}
else {
target[prop] = this._props[key];
}
}
}
}
}
onPropChange(key) {
if (this._propBinder[key]) {
for (const { target, prop } of this._propBinder[key]) {
if (typeof target === "function") {
target(this._props[key]);
}
else {
target[prop] = this._props[key];
}
}
}
}
}
class CCPureView extends CCView {
constructor() {
super();
this._propBinder = {};
}
onLoad() { }
}
exports.CCPureView = CCPureView;
class CCPureSubview extends CCSubview {
constructor() {
super();
this._propBinder = {};
}
}
exports.CCPureSubview = CCPureSubview;
function applyMixins(derivedCtor, constructors) {
constructors.forEach((baseCtor) => {
Object.getOwnPropertyNames(baseCtor.prototype).forEach((name) => {
if (name !== "constructor") {
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseCtor.prototype, name));
}
});
});
}
applyMixins(CCPureView, [PureViewBase]);
applyMixins(CCPureSubview, [PureViewBase]);
cc._RF.pop();