@cc-component/cc-ex-component 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,21 +5,18 @@ const { ccclass, property } = _decorator;
|
|
|
5
5
|
|
|
6
6
|
@ccclass('BaseReference')
|
|
7
7
|
export class BaseReference extends Component {
|
|
8
|
+
refMap: Map<string, string> = new Map();
|
|
8
9
|
private rc: ReferenceComponent;
|
|
9
|
-
private isInit: boolean = false;
|
|
10
|
-
private isLoad: boolean = false;
|
|
11
10
|
private vmParams: any;
|
|
12
11
|
viewModel: BaseViewModelData;
|
|
13
12
|
param: any;
|
|
14
13
|
initReferenceCollector() {
|
|
15
|
-
if (this.isInit) return;
|
|
16
|
-
this.isInit = true;
|
|
17
14
|
this.rc = this.getComponent(ReferenceComponent);
|
|
15
|
+
this.refMap.forEach((value, key) => { this.defineProperty(key); });
|
|
16
|
+
console.error("1111")
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
onLoadFinish() {
|
|
21
|
-
if (this.isLoad) return;
|
|
22
|
-
this.isLoad = true;
|
|
23
20
|
if (this.vmParams) this.viewModel?.refreshUI(this.vmParams)
|
|
24
21
|
}
|
|
25
22
|
//#endregion
|
package/assets/core/ViewModel.ts
CHANGED
|
@@ -84,9 +84,7 @@ export function Bind<T extends Component>(dataPath: string, param?: IBindingData
|
|
|
84
84
|
dataPath: dataPath, type: null, reset: param?.reset, event: param?.event,
|
|
85
85
|
itemSize: null,
|
|
86
86
|
cellForItemAt: null,
|
|
87
|
-
numberOfItems:
|
|
88
|
-
throw new Error('Function not implemented.');
|
|
89
|
-
}
|
|
87
|
+
numberOfItems: null,
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
bindingMap.get(className)!.set(propertyKey, data);
|
|
@@ -311,7 +309,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
311
309
|
com_btn.node.active = value ?? true;
|
|
312
310
|
|
|
313
311
|
//事件
|
|
314
|
-
com_btn.node.off(Button.EventType.CLICK, com_btn['btnCall']
|
|
312
|
+
com_btn.node.off(Button.EventType.CLICK, com_btn['btnCall']);
|
|
315
313
|
tempData.skip = true;
|
|
316
314
|
const btnCall = (btn) => {
|
|
317
315
|
tempData.value = btn.node.active
|
|
@@ -320,7 +318,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
320
318
|
self[`onClick_${sx}`]?.(btn)
|
|
321
319
|
}
|
|
322
320
|
com_btn['btnCall'] = btnCall
|
|
323
|
-
com_btn.node.on(Button.EventType.CLICK, com_btn['btnCall']
|
|
321
|
+
com_btn.node.on(Button.EventType.CLICK, com_btn['btnCall']);
|
|
324
322
|
break;
|
|
325
323
|
case 'cc.ProgressBar':
|
|
326
324
|
if (data.reset) {
|
|
@@ -534,12 +532,15 @@ export function BindViewModel(initialValue?: any) {
|
|
|
534
532
|
|
|
535
533
|
// 定义装饰器
|
|
536
534
|
export function Ref(target: any, propertyKey: string) {
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
535
|
+
const refMap: Map<string, string> = target.constructor.prototype.refMap
|
|
536
|
+
refMap.set(propertyKey, propertyKey)
|
|
537
|
+
if (refMap.size <= 0) {
|
|
538
|
+
const originalOnLoad = target.constructor.prototype.onLoad;
|
|
539
|
+
target.constructor.prototype.onLoad = function (this: any) {
|
|
540
|
+
this.initReferenceCollector();
|
|
541
|
+
this.defineProperty(propertyKey);
|
|
542
|
+
originalOnLoad?.call(this);
|
|
543
|
+
this.onLoadFinish();
|
|
544
|
+
};
|
|
545
|
+
}
|
|
544
546
|
}
|
|
545
|
-
|