@azrico/webobject 1.4.16 → 1.4.17

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.
@@ -73,6 +73,7 @@ export declare class WebObject extends SimpleObject {
73
73
  onDelete(...p: any): Promise<any>;
74
74
  onLoad(...p: any): Promise<any>;
75
75
  onSave(...p: any): Promise<any>;
76
+ getSaveResult(original?: boolean): any;
76
77
  onNew(...p: any): Promise<any>;
77
78
  /**
78
79
  * get a single web object
@@ -20,6 +20,8 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
20
20
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
21
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
22
22
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
24
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
23
25
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
24
26
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
25
27
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -407,10 +409,8 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
407
409
  key: "onSave",
408
410
  value: function () {
409
411
  var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
410
- var _this3 = this,
411
- _this$manager4;
412
+ var _this$manager4;
412
413
  var srObject,
413
- actual_sr,
414
414
  _this$manager3,
415
415
  _len3,
416
416
  p,
@@ -420,25 +420,13 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
420
420
  while (1) switch (_context8.prev = _context8.next) {
421
421
  case 0:
422
422
  if (!this.isSaved) {
423
- _context8.next = 10;
423
+ _context8.next = 8;
424
424
  break;
425
425
  }
426
426
  this.apply_changes();
427
427
  srObject = this.getSaveResult(true);
428
- if (!(srObject != null)) {
429
- _context8.next = 10;
430
- break;
431
- }
432
- //we may have some extra data in the save result.
433
- //try to find the main data
434
- if (Array.isArray(srObject)) {
435
- actual_sr = srObject.find(function (s) {
436
- return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
437
- });
438
- if (actual_sr) srObject = actual_sr;
439
- }
440
428
  if (!_classPrivateMethodGet(this, _isValidSR, _isValidSR2).call(this, srObject)) {
441
- _context8.next = 10;
429
+ _context8.next = 8;
442
430
  break;
443
431
  }
444
432
  if (srObject.insertedId || srObject._id) {
@@ -447,17 +435,17 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
447
435
  if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
448
436
  this._index_value = Number(srObject._index_value);
449
437
  }
450
- _context8.next = 10;
438
+ _context8.next = 8;
451
439
  return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.event_run("on_id_change");
452
- case 10:
440
+ case 8:
453
441
  for (_len3 = _args8.length, p = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
454
442
  p[_key3] = _args8[_key3];
455
443
  }
456
- _context8.next = 13;
444
+ _context8.next = 11;
457
445
  return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onSave.apply(_this$manager4, p);
458
- case 13:
446
+ case 11:
459
447
  return _context8.abrupt("return", _context8.sent);
460
- case 14:
448
+ case 12:
461
449
  case "end":
462
450
  return _context8.stop();
463
451
  }
@@ -468,6 +456,21 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
468
456
  }
469
457
  return onSave;
470
458
  }()
459
+ }, {
460
+ key: "getSaveResult",
461
+ value: function getSaveResult() {
462
+ var _this3 = this;
463
+ var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
464
+ var srObject = _get(_getPrototypeOf(WebObject.prototype), "getSaveResult", this).call(this, original);
465
+ if (!srObject) return false;
466
+ if (Array.isArray(srObject)) {
467
+ var actual_sr = srObject.find(function (s) {
468
+ return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
469
+ });
470
+ if (actual_sr) srObject = actual_sr;
471
+ }
472
+ return srObject;
473
+ }
471
474
  }, {
472
475
  key: "onNew",
473
476
  value: function () {
@@ -766,7 +769,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
766
769
  }(_SimpleObject2["default"]);
767
770
  exports.WebObject = WebObject;
768
771
  function _isValidSR2(s) {
769
- if (_typeof(s) !== "object" && s == null) return false;
772
+ if (_typeof(s) !== "object" || s == null || !s) return false;
770
773
  return s.insertedId || s._id || s._index_value && !Number.isNaN(s._index_value);
771
774
  }
772
775
  _defineProperty(WebObject, "__web_path", "");
@@ -792,7 +792,9 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
792
792
  key: "getSaveResult",
793
793
  value: function getSaveResult() {
794
794
  var original = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
795
- if (this.isSaved) return this.__saveResultObject;
795
+ if (this.isSaved) {
796
+ return this.__saveResultObject;
797
+ }
796
798
  return false;
797
799
  }
798
800
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.4.16",
3
+ "version": "1.4.17",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",