@galacean/engine-loader 1.1.0-beta.18 → 1.1.0-beta.19

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.
@@ -543,11 +543,17 @@ var ReflectionParser = /*#__PURE__*/ function() {
543
543
  });
544
544
  };
545
545
  _proto.parseClassObject = function parseClassObject(item) {
546
+ var _this = this;
546
547
  var Class = miniprogram.Loader.getClass(item.class);
547
548
  var _item_constructParams;
548
549
  var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
549
- var instance = _construct(Class, [].concat(params));
550
- return this.parsePropsAndMethods(instance, item);
550
+ return Promise.all(params.map(function(param) {
551
+ return _this.parseBasicType(param);
552
+ })).then(function(resultParams) {
553
+ return _construct(Class, [].concat(resultParams));
554
+ }).then(function(instance) {
555
+ return _this.parsePropsAndMethods(instance, item);
556
+ });
551
557
  };
552
558
  _proto.parsePropsAndMethods = function parsePropsAndMethods(instance, item) {
553
559
  var promises = [];
@@ -555,16 +561,14 @@ var ReflectionParser = /*#__PURE__*/ function() {
555
561
  for(var methodName in item.methods){
556
562
  var methodParams = item.methods[methodName];
557
563
  for(var i = 0, count = methodParams.length; i < count; i++){
558
- var params = methodParams[i];
559
- var promise = this.parseMethod(instance, methodName, params);
560
- promises.push(promise);
564
+ promises.push(this.parseMethod(instance, methodName, methodParams[i]));
561
565
  }
562
566
  }
563
567
  }
564
568
  if (item.props) {
565
569
  var _this = this, _loop = function(key) {
566
570
  var value = item.props[key];
567
- var promise = _this.parseBasicType(value).then(function(v) {
571
+ var promise = _this.parseBasicType(value, instance[key]).then(function(v) {
568
572
  return instance[key] = v;
569
573
  });
570
574
  promises.push(promise);
@@ -586,7 +590,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
586
590
  return (_instance = instance)[methodName].apply(_instance, [].concat(result));
587
591
  });
588
592
  };
589
- _proto.parseBasicType = function parseBasicType(value) {
593
+ _proto.parseBasicType = function parseBasicType(value, originValue) {
590
594
  var _this = this;
591
595
  if (Array.isArray(value)) {
592
596
  return Promise.all(value.map(function(item) {
@@ -603,13 +607,33 @@ var ReflectionParser = /*#__PURE__*/ function() {
603
607
  } else if (ReflectionParser._isEntityRef(value)) {
604
608
  // entity reference
605
609
  return Promise.resolve(this._context.entityMap.get(value.entityId));
606
- } else {
607
- // basic type
608
- return Promise.resolve(value);
610
+ } else if (originValue) {
611
+ var _this1 = this, _loop = function(key) {
612
+ if (key === "methods") {
613
+ var methods = value[key];
614
+ for(var methodName in methods){
615
+ var methodParams = methods[methodName];
616
+ for(var i = 0, count = methodParams.length; i < count; i++){
617
+ var params = methodParams[i];
618
+ var promise = _this1.parseMethod(originValue, methodName, params);
619
+ promises.push(promise);
620
+ }
621
+ }
622
+ } else {
623
+ promises.push(_this1.parseBasicType(value[key], originValue[key]).then(function(v) {
624
+ return originValue[key] = v;
625
+ }));
626
+ }
627
+ };
628
+ var promises = [];
629
+ for(var key in value)_loop(key);
630
+ return Promise.all(promises).then(function() {
631
+ return originValue;
632
+ });
609
633
  }
610
- } else {
611
- return Promise.resolve(value);
612
634
  }
635
+ // primitive type
636
+ return Promise.resolve(value);
613
637
  };
614
638
  _proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
615
639
  // @ts-ignore
package/dist/module.js CHANGED
@@ -538,11 +538,17 @@ var ReflectionParser = /*#__PURE__*/ function() {
538
538
  });
539
539
  };
540
540
  _proto.parseClassObject = function parseClassObject(item) {
541
+ var _this = this;
541
542
  var Class = Loader.getClass(item.class);
542
543
  var _item_constructParams;
543
544
  var params = (_item_constructParams = item.constructParams) != null ? _item_constructParams : [];
544
- var instance = _construct(Class, [].concat(params));
545
- return this.parsePropsAndMethods(instance, item);
545
+ return Promise.all(params.map(function(param) {
546
+ return _this.parseBasicType(param);
547
+ })).then(function(resultParams) {
548
+ return _construct(Class, [].concat(resultParams));
549
+ }).then(function(instance) {
550
+ return _this.parsePropsAndMethods(instance, item);
551
+ });
546
552
  };
547
553
  _proto.parsePropsAndMethods = function parsePropsAndMethods(instance, item) {
548
554
  var promises = [];
@@ -550,16 +556,14 @@ var ReflectionParser = /*#__PURE__*/ function() {
550
556
  for(var methodName in item.methods){
551
557
  var methodParams = item.methods[methodName];
552
558
  for(var i = 0, count = methodParams.length; i < count; i++){
553
- var params = methodParams[i];
554
- var promise = this.parseMethod(instance, methodName, params);
555
- promises.push(promise);
559
+ promises.push(this.parseMethod(instance, methodName, methodParams[i]));
556
560
  }
557
561
  }
558
562
  }
559
563
  if (item.props) {
560
564
  var _this = this, _loop = function(key) {
561
565
  var value = item.props[key];
562
- var promise = _this.parseBasicType(value).then(function(v) {
566
+ var promise = _this.parseBasicType(value, instance[key]).then(function(v) {
563
567
  return instance[key] = v;
564
568
  });
565
569
  promises.push(promise);
@@ -581,7 +585,7 @@ var ReflectionParser = /*#__PURE__*/ function() {
581
585
  return (_instance = instance)[methodName].apply(_instance, [].concat(result));
582
586
  });
583
587
  };
584
- _proto.parseBasicType = function parseBasicType(value) {
588
+ _proto.parseBasicType = function parseBasicType(value, originValue) {
585
589
  var _this = this;
586
590
  if (Array.isArray(value)) {
587
591
  return Promise.all(value.map(function(item) {
@@ -598,13 +602,33 @@ var ReflectionParser = /*#__PURE__*/ function() {
598
602
  } else if (ReflectionParser._isEntityRef(value)) {
599
603
  // entity reference
600
604
  return Promise.resolve(this._context.entityMap.get(value.entityId));
601
- } else {
602
- // basic type
603
- return Promise.resolve(value);
605
+ } else if (originValue) {
606
+ var _this1 = this, _loop = function(key) {
607
+ if (key === "methods") {
608
+ var methods = value[key];
609
+ for(var methodName in methods){
610
+ var methodParams = methods[methodName];
611
+ for(var i = 0, count = methodParams.length; i < count; i++){
612
+ var params = methodParams[i];
613
+ var promise = _this1.parseMethod(originValue, methodName, params);
614
+ promises.push(promise);
615
+ }
616
+ }
617
+ } else {
618
+ promises.push(_this1.parseBasicType(value[key], originValue[key]).then(function(v) {
619
+ return originValue[key] = v;
620
+ }));
621
+ }
622
+ };
623
+ var promises = [];
624
+ for(var key in value)_loop(key);
625
+ return Promise.all(promises).then(function() {
626
+ return originValue;
627
+ });
604
628
  }
605
- } else {
606
- return Promise.resolve(value);
607
629
  }
630
+ // primitive type
631
+ return Promise.resolve(value);
608
632
  };
609
633
  _proto._getEntityByConfig = function _getEntityByConfig(entityConfig) {
610
634
  // @ts-ignore