@cc-component/cc-ex-component 1.9.9 → 2.0.0
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.
package/assets/core/ViewModel.ts
CHANGED
|
@@ -20,6 +20,8 @@ import { YXPagelayout } from '../lib/collectView/lib_collect/yx-page-layout';
|
|
|
20
20
|
import { SpriteFrame } from 'cc';
|
|
21
21
|
import { tween } from 'cc';
|
|
22
22
|
import { v3 } from 'cc';
|
|
23
|
+
import { BaseReference } from '../core/BaseReference';
|
|
24
|
+
import { on } from 'events';
|
|
23
25
|
|
|
24
26
|
interface IBindingData extends ITableViewEvents, IBindingDataEvents {
|
|
25
27
|
dataPath: string;
|
|
@@ -105,6 +107,7 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
|
|
|
105
107
|
const instance = new constructor();
|
|
106
108
|
this[baseData] = this._makeReactive(instance, baseData);
|
|
107
109
|
|
|
110
|
+
const self = this
|
|
108
111
|
const map = bindingMap.get(className)
|
|
109
112
|
for (const [propertyKey, value] of map) {
|
|
110
113
|
//属性绑定
|
|
@@ -115,7 +118,15 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
|
|
|
115
118
|
const com = this[propertyKey];
|
|
116
119
|
const classname = js.getClassName(com)
|
|
117
120
|
value.type = classname
|
|
118
|
-
|
|
121
|
+
//绑定自定义的继承BaseReference 的类的viewModel
|
|
122
|
+
if (com instanceof BaseReference) {
|
|
123
|
+
const onLoadFinished = com.onLoadFinished;
|
|
124
|
+
com.onLoadFinished = function () {
|
|
125
|
+
self.viewModel[propertyKey] = com.viewModel
|
|
126
|
+
onLoadFinished.call(com);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//console.log('属性绑定', propertyKey, value.type, com, this)
|
|
119
130
|
// 记录绑定关系到实例
|
|
120
131
|
//this._bindings.push({ uiProp: value.propertyKey, dataPath: value.dataPath });
|
|
121
132
|
this._bindings[value.dataPath] = value.propertyKey;
|
|
@@ -597,10 +608,12 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
597
608
|
};
|
|
598
609
|
}
|
|
599
610
|
|
|
611
|
+
|
|
612
|
+
|
|
600
613
|
function updateStatus(data: IBindingData, com: Component, value: any, self: any) {
|
|
601
614
|
const sx = data.dataPath.split('.').pop();
|
|
602
615
|
const tempData = { value: value, skip: false }
|
|
603
|
-
//console.log("updateStatus", data.propertyKey)
|
|
616
|
+
// console.log("updateStatus", data.propertyKey, data.type, com)
|
|
604
617
|
switch (data.type) {
|
|
605
618
|
case 'cc.Label':
|
|
606
619
|
if (data.reset) {
|
|
@@ -826,11 +839,13 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
826
839
|
case 'cc.Node':
|
|
827
840
|
break;
|
|
828
841
|
default: {
|
|
829
|
-
|
|
842
|
+
if (com) {
|
|
843
|
+
// console.error(`请检查类型: ${data.type}---${data.dataPath}--${data.propertyKey}`);
|
|
844
|
+
}
|
|
830
845
|
break
|
|
831
846
|
}
|
|
832
|
-
}
|
|
833
847
|
|
|
848
|
+
}
|
|
834
849
|
}
|
|
835
850
|
// assets/cc-ex-component/core/ViewModel.ts
|
|
836
851
|
|