@azrico/webobject 1.2.33 → 1.2.34

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.
@@ -355,22 +355,24 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
355
355
  * Apply the changes and empty the delta object
356
356
  */
357
357
  function apply_changes() {
358
- if (!this.__use_delta) {
359
- //in this mode , we track changes by updating the original product
360
- this.setOriginal();
358
+ try {
359
+ if (!this.__use_delta) {
360
+ //in this mode , we track changes by updating the original product
361
+ this.setOriginal();
362
+ return true;
363
+ }
364
+ if (!this.isChanged) {
365
+ console.warn("No changes to apply");
366
+ return false;
367
+ }
368
+ for (var key in this.__delta) {
369
+ var nv = this.__delta[key];
370
+ this[key] = nv;
371
+ }
361
372
  return true;
362
- }
363
- if (!this.isChanged) {
364
- console.warn("No changes to apply");
373
+ } finally {
365
374
  this.clear_changes();
366
- return false;
367
- }
368
- for (var key in this.__delta) {
369
- var nv = this.__delta[key];
370
- this[key] = nv;
371
375
  }
372
- this.clear_changes();
373
- return true;
374
376
  }
375
377
  }, {
376
378
  key: "clear_changes",
@@ -398,23 +400,28 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
398
400
  /* -------------------------------------------------------------------------- */
399
401
  function get() {
400
402
  var _this2 = this;
401
- if (this.__use_delta) return !(0, _object.object_isEmpty)(this.__delta);else {
402
- var orig = this.getOriginal();
403
- if (!orig) return false; //we dont know if anything has changed
404
- /* if object is not using delta mode, check changes by comparing changable fields with original object */
405
- if (Array.isArray(this.__changeables)) {
406
- //console.log("chk", this.__changeables, "for changes");
407
- return this.__changeables.find(function (c) {
408
- return !(0, _object.object_equals)(_this2[c], orig[c]);
409
- }) != undefined;
410
- } else {
411
- /* check all fields */
412
- for (var key in this) {
413
- if (key.startsWith("__")) continue;
414
- if (!(0, _object.object_equals)(this[key], orig[key])) return true;
415
- }
416
- return false;
403
+ ////const deltaIsBlank = object_isEmpty(this.__delta);
404
+ ////if (!deltaIsBlank) return true; //delta is not blank, definitely changed
405
+ ////if (this.__use_delta) return !deltaIsBlank; //trust the delta.
406
+ if (this.__use_delta) return !(0, _object.object_isEmpty)(this.__delta);
407
+ /* -------------------------------------------------------------------------- */
408
+ /* check the properties one by one */
409
+ /* -------------------------------------------------------------------------- */
410
+ var orig = this.getOriginal();
411
+ if (!orig) return false; //we dont know if anything has changed
412
+ /* if object is not using delta mode, check changes by comparing changable fields with original object */
413
+ if (Array.isArray(this.__changeables)) {
414
+ //console.log("chk", this.__changeables, "for changes");
415
+ return this.__changeables.find(function (c) {
416
+ return !(0, _object.object_equals)(_this2[c], orig[c]);
417
+ }) != undefined;
418
+ } else {
419
+ /* check all fields */
420
+ for (var key in this) {
421
+ if (key.startsWith("__")) continue;
422
+ if (!(0, _object.object_equals)(this[key], orig[key])) return true;
417
423
  }
424
+ return false;
418
425
  }
419
426
  return false;
420
427
  }
@@ -819,7 +826,8 @@ function _getSubProperty2(key, subkey) {
819
826
  return subobj[subkey];
820
827
  }
821
828
  function _setProperty2(key, value) {
822
- if (this.__use_delta) this.__delta[key] = value;else this[key] = value;
829
+ this.__delta[key] = value; //always update delta to keep track of changes
830
+ if (!this.__use_delta) this[key] = value; //on noDelta mode, also update the obj
823
831
  return true;
824
832
  }
825
833
  function _setDefaultProperty2(key, value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.2.33",
3
+ "version": "1.2.34",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",