mirror of
https://github.com/wsssheep/cocos_creator_mvvm_tools.git
synced 2026-05-06 21:40:39 +08:00
将部分组件的 onValueInit 执行延后到 start 生命周期函数执行,避免初始化顺序错误
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
# cocos_creator_mvvm_tools 0.1.0
|
||||
|
||||
### 版本说明
|
||||
v0.1.0 - Typescript 的 稳定版本
|
||||
v0.1.1 - 修复VMParent onLoad顺序的错误
|
||||
|
||||
### 简介
|
||||
|
||||
适用于cocos creator 的 mvvm 的工具 集,摆脱传统MVC设置节点属性来控制 UI 的方式。你可以更快捷、更细致地处理UI的表现效果。不写一行代码完成复杂的显示逻辑。设计这个框架的目地就是为了解决 数据和节点状态变化切换的麻烦关系。
|
||||
|
||||
@@ -5,7 +5,6 @@ const {VM} = require('./../Script/modelView/ViewModel');
|
||||
//JS调用用例
|
||||
cc.Class({
|
||||
extends: VMParent.default,
|
||||
|
||||
ctor:function(){
|
||||
//data 数据在这里定义
|
||||
this.data = {
|
||||
@@ -15,8 +14,7 @@ cc.Class({
|
||||
},
|
||||
|
||||
properties: {
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
onBind(){
|
||||
|
||||
@@ -41,8 +41,8 @@
|
||||
},
|
||||
"_scale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0.6854670188534268,
|
||||
"y": 0.6854670188534268,
|
||||
"x": 0.5321614583333333,
|
||||
"y": 0.5321614583333333,
|
||||
"z": 1
|
||||
},
|
||||
"_quat": {
|
||||
@@ -52,7 +52,6 @@
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_zIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"autoReleaseAssets": false,
|
||||
"_id": "733f22af-1d8a-4e99-9b5b-0b9dc406cba7"
|
||||
@@ -121,7 +120,6 @@
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_zIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "cdSHhfghlMqorynGdDUdR7"
|
||||
},
|
||||
@@ -182,7 +180,6 @@
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_zIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "961r8J0RdADZzxOKPEhJhi"
|
||||
},
|
||||
@@ -272,7 +269,6 @@
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_zIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "0421LPCb1PtICCCd1ul3H8"
|
||||
},
|
||||
@@ -313,109 +309,6 @@
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_position": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_scale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_quat": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_zIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "17CLE4Th1BwKMF3B/MFSfL"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"_srcBlendFactor": 1,
|
||||
"_dstBlendFactor": 771,
|
||||
"_useOriginalSize": false,
|
||||
"_string": "Label",
|
||||
"_N$string": "Label",
|
||||
"_fontSize": 40,
|
||||
"_lineHeight": 40,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 0,
|
||||
"_id": "d4RuMWbYNHdbBe0xeyoMZh"
|
||||
},
|
||||
{
|
||||
"__type__": "545c05XsG9GDJispEGWKvYv",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"watchPath": "*.name",
|
||||
"labelType": "cc.Label",
|
||||
"templateMode": false,
|
||||
"watchPathArr": [],
|
||||
"_id": "d3Shce7oRBPoOeQr3ulNkp"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "New Label",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 5
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_level": 2,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 10
|
||||
},
|
||||
{
|
||||
"__id__": 11
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 97.87,
|
||||
"height": 40
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_position": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
@@ -439,7 +332,6 @@
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"_zIndex": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "38wRt+6pNDvrXYxmEIdn6e"
|
||||
},
|
||||
@@ -448,11 +340,9 @@
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 9
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"_srcBlendFactor": 1,
|
||||
"_dstBlendFactor": 771,
|
||||
"_useOriginalSize": false,
|
||||
"_string": "Label",
|
||||
"_N$string": "Label",
|
||||
@@ -462,12 +352,116 @@
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_batchAsBitmap": false,
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 0,
|
||||
"_N$cacheMode": 0,
|
||||
"_id": "38tPozXqVDVKD0GnkkXeJV"
|
||||
},
|
||||
{
|
||||
"__type__": "545c05XsG9GDJispEGWKvYv",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 6
|
||||
},
|
||||
"_enabled": true,
|
||||
"watchPath": "*.count",
|
||||
"labelType": "cc.Label",
|
||||
"templateMode": false,
|
||||
"watchPathArr": [],
|
||||
"_id": "8dIuEGcGpGg6cRjHn2ee0J"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Node",
|
||||
"_name": "New Label",
|
||||
"_objFlags": 0,
|
||||
"_parent": {
|
||||
"__id__": 5
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_level": 2,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 10
|
||||
},
|
||||
{
|
||||
"__id__": 11
|
||||
}
|
||||
],
|
||||
"_prefab": null,
|
||||
"_opacity": 255,
|
||||
"_color": {
|
||||
"__type__": "cc.Color",
|
||||
"r": 255,
|
||||
"g": 255,
|
||||
"b": 255,
|
||||
"a": 255
|
||||
},
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 97.87,
|
||||
"height": 40
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
"x": 0.5,
|
||||
"y": 0.5
|
||||
},
|
||||
"_position": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0
|
||||
},
|
||||
"_scale": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 1,
|
||||
"y": 1,
|
||||
"z": 1
|
||||
},
|
||||
"_rotationX": 0,
|
||||
"_rotationY": 0,
|
||||
"_quat": {
|
||||
"__type__": "cc.Quat",
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 0,
|
||||
"w": 1
|
||||
},
|
||||
"_skewX": 0,
|
||||
"_skewY": 0,
|
||||
"groupIndex": 0,
|
||||
"_id": "17CLE4Th1BwKMF3B/MFSfL"
|
||||
},
|
||||
{
|
||||
"__type__": "cc.Label",
|
||||
"_name": "",
|
||||
"_objFlags": 0,
|
||||
"node": {
|
||||
"__id__": 9
|
||||
},
|
||||
"_enabled": true,
|
||||
"_useOriginalSize": false,
|
||||
"_string": "Label",
|
||||
"_N$string": "Label",
|
||||
"_fontSize": 40,
|
||||
"_lineHeight": 40,
|
||||
"_enableWrapText": true,
|
||||
"_N$file": null,
|
||||
"_isSystemFontUsed": true,
|
||||
"_spacingX": 0,
|
||||
"_batchAsBitmap": false,
|
||||
"_N$horizontalAlign": 1,
|
||||
"_N$verticalAlign": 1,
|
||||
"_N$fontFamily": "Arial",
|
||||
"_N$overflow": 0,
|
||||
"_N$cacheMode": 0,
|
||||
"_id": "d4RuMWbYNHdbBe0xeyoMZh"
|
||||
},
|
||||
{
|
||||
"__type__": "545c05XsG9GDJispEGWKvYv",
|
||||
"_name": "",
|
||||
@@ -476,11 +470,11 @@
|
||||
"__id__": 9
|
||||
},
|
||||
"_enabled": true,
|
||||
"watchPath": "*.count",
|
||||
"watchPath": "*.name",
|
||||
"labelType": "cc.Label",
|
||||
"templateMode": false,
|
||||
"watchPathArr": [],
|
||||
"_id": "8dIuEGcGpGg6cRjHn2ee0J"
|
||||
"_id": "d3Shce7oRBPoOeQr3ulNkp"
|
||||
},
|
||||
{
|
||||
"__type__": "cd4d1V64Q1G3JTU7YerTm72",
|
||||
|
||||
@@ -70,11 +70,15 @@ export default class VMLabel extends VMBase {
|
||||
this.originText = this.getLabelValue();
|
||||
this.parseTemplate();
|
||||
}
|
||||
this.onValueInit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
start(){
|
||||
if (!CC_EDITOR) return;
|
||||
this.onValueInit();
|
||||
}
|
||||
|
||||
|
||||
// //多路径监听方式
|
||||
// protected setMultPathEvent(enabled: boolean = true) {
|
||||
|
||||
@@ -37,7 +37,6 @@ export default class VMParent extends cc.Component {
|
||||
*/
|
||||
protected onLoad() {
|
||||
if (this.data == null) return;
|
||||
|
||||
this.tag = '_temp' + '<'+ this.node.uuid.replace('.', '') + '>';
|
||||
VM.add(this.data, this.tag);
|
||||
//cc.log(VM['_mvs'],tag)
|
||||
|
||||
@@ -51,8 +51,9 @@ export default class VMProgress extends VMCustom {
|
||||
}
|
||||
|
||||
start () {
|
||||
if (CC_EDITOR) return;
|
||||
this.onValueInit();
|
||||
if (!CC_EDITOR){
|
||||
this.onValueInit();
|
||||
}
|
||||
}
|
||||
|
||||
onValueInit() {
|
||||
|
||||
@@ -136,11 +136,13 @@ export default class VMState extends VMBase {
|
||||
this.watchNodes = this.watchNodes.concat(this.node.children);
|
||||
}
|
||||
|
||||
if(this.enabled)this.onValueInit();
|
||||
|
||||
}
|
||||
|
||||
start () {
|
||||
|
||||
if(this.enabled){
|
||||
this.onValueInit();
|
||||
}
|
||||
}
|
||||
|
||||
//当值初始化时
|
||||
|
||||
Reference in New Issue
Block a user