@cc-component/cc-ex-component 1.3.9 → 1.4.1
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
|
@@ -57,10 +57,10 @@ interface ICollectViewEvents {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// 全局存储绑定关系: { className -> { uiProp: dataPath } }
|
|
60
|
-
const bindingMap = new Map<
|
|
60
|
+
const bindingMap = new Map<any, Map<string, IBindingData>>();
|
|
61
61
|
const baseData = 'viewModel'
|
|
62
62
|
const skip = "$"
|
|
63
|
-
export const refMap: Map<
|
|
63
|
+
export const refMap: Map<any, string[]> = new Map();
|
|
64
64
|
|
|
65
65
|
// const comType = {
|
|
66
66
|
// "cc.Sprite": typeof Sprite,
|
|
@@ -83,12 +83,12 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
|
|
|
83
83
|
*/
|
|
84
84
|
target.prototype.onLoad = function () {
|
|
85
85
|
onLoad.call(this);
|
|
86
|
-
const className = js.getClassName(target);
|
|
86
|
+
const className = target.prototype//js.getClassName(target);
|
|
87
87
|
if (!bindingMap.has(className)) {
|
|
88
88
|
bindingMap.set(className, new Map());
|
|
89
89
|
}
|
|
90
90
|
this.className = className;
|
|
91
|
-
|
|
91
|
+
console.log('onLoad我的', this.node.name, this.className)
|
|
92
92
|
if (!this._bindings) this._bindings = [];
|
|
93
93
|
|
|
94
94
|
const map = bindingMap.get(className)
|
|
@@ -130,7 +130,7 @@ export function BindViewModel<T extends new () => any>(constructor: T) {
|
|
|
130
130
|
export function Bind<T extends Component>(path?: string, param?: IBindingDataEvents) {
|
|
131
131
|
const dataPath = baseData + '.' + path;
|
|
132
132
|
return function (target: any, propertyKey: string) {
|
|
133
|
-
const className =
|
|
133
|
+
const className = target.constructor.prototype
|
|
134
134
|
const data: IBindingData = {
|
|
135
135
|
propertyKey: propertyKey,
|
|
136
136
|
dataPath: dataPath, type: className, reset: param?.reset, event: param?.event,
|
|
@@ -152,7 +152,7 @@ export function Bind<T extends Component>(path?: string, param?: IBindingDataEve
|
|
|
152
152
|
export function BindTable<T extends Component>(dataPath: string, param?: ITableViewEvents) {
|
|
153
153
|
dataPath = baseData + '.' + dataPath;
|
|
154
154
|
return function (target: any, propertyKey: string) {
|
|
155
|
-
const className =
|
|
155
|
+
const className = target
|
|
156
156
|
const data: IBindingData = {
|
|
157
157
|
propertyKey: propertyKey,
|
|
158
158
|
|
|
@@ -171,8 +171,7 @@ export function BindTable<T extends Component>(dataPath: string, param?: ITableV
|
|
|
171
171
|
export function BindCollect<T extends Component>(dataPath: string, param?: ICollectViewEvents) {
|
|
172
172
|
dataPath = baseData + '.' + dataPath;
|
|
173
173
|
return function (target: any, propertyKey: string) {
|
|
174
|
-
const className =
|
|
175
|
-
|
|
174
|
+
const className = target
|
|
176
175
|
const data: IBindingData = {
|
|
177
176
|
propertyKey: propertyKey,
|
|
178
177
|
dataPath: dataPath, type: null,
|
|
@@ -203,7 +202,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
203
202
|
touch_slide = 'CALL_SLIDE_EVENT'
|
|
204
203
|
touch_toggle = 'CALL_TOGGLE_EVENT'
|
|
205
204
|
touch_editbox = 'CALL_EDITBOX_EVENT'
|
|
206
|
-
className:
|
|
205
|
+
className: any
|
|
207
206
|
// 创建响应式数据
|
|
208
207
|
_makeReactive<T extends object>(obj: T, pathPrefix: string): T {
|
|
209
208
|
const self = this as any;
|
|
@@ -251,7 +250,7 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
251
250
|
if (fullPath === dataPath) {
|
|
252
251
|
const com = this[uiProp]
|
|
253
252
|
if (com) {
|
|
254
|
-
const classname =
|
|
253
|
+
const classname = this.constructor.prototype
|
|
255
254
|
const data = bindingMap.get(classname).get(uiProp)
|
|
256
255
|
const value = this._getNestedValue(this, data.dataPath);
|
|
257
256
|
updateStatus(data, com, value, this)
|
|
@@ -269,6 +268,12 @@ export function ViewModel<T extends new (...args: any[]) => Component>(Base: T)
|
|
|
269
268
|
|
|
270
269
|
}
|
|
271
270
|
|
|
271
|
+
// protected onLoad(): void {
|
|
272
|
+
// super.onLoad()
|
|
273
|
+
// console.error('打印名称', js.getClassName(this))
|
|
274
|
+
// const className = js.getClassName(this)
|
|
275
|
+
// // ecs.getSingleton()
|
|
276
|
+
// }
|
|
272
277
|
// 在 withDataBinding 返回的 class 中
|
|
273
278
|
protected onDestroy(): void {
|
|
274
279
|
this.unbindViewModel();
|
|
@@ -666,8 +671,7 @@ function updateStatus(data: IBindingData, com: Component, value: any, self: any)
|
|
|
666
671
|
|
|
667
672
|
// 定义装饰器
|
|
668
673
|
export function Ref(target: any, propertyKey: string) {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
const refList = refMap.get(className)
|
|
674
|
+
if (!refMap.has(target)) { refMap.set(target, []) }
|
|
675
|
+
const refList = refMap.get(target)
|
|
672
676
|
refList.push(propertyKey)
|
|
673
677
|
}
|