@azrico/webobject 1.2.32 → 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.
|
@@ -33,7 +33,7 @@ export declare class ObjectManager<ObjType extends SimpleObject> {
|
|
|
33
33
|
getSaveResult(): any;
|
|
34
34
|
getSaveResultType(): saveResultType | null;
|
|
35
35
|
setSaveResult(toObj: any, type: saveResultType): void | undefined;
|
|
36
|
-
apply_changes():
|
|
36
|
+
apply_changes(): boolean | undefined;
|
|
37
37
|
getValue(key: PropOf<ObjType>, original?: boolean): import("./SimpleObject").PropType<ObjType, any> | undefined;
|
|
38
38
|
get: (key: PropOf<ObjType>, original?: boolean) => import("./SimpleObject").PropType<ObjType, any> | undefined;
|
|
39
39
|
/**
|
|
@@ -60,9 +60,9 @@ export declare class SimpleObject extends MapableObject {
|
|
|
60
60
|
/**
|
|
61
61
|
* Apply the changes and empty the delta object
|
|
62
62
|
*/
|
|
63
|
-
apply_changes():
|
|
64
|
-
clear_changes():
|
|
65
|
-
clear_cache():
|
|
63
|
+
apply_changes(): boolean;
|
|
64
|
+
clear_changes(): boolean;
|
|
65
|
+
clear_cache(): boolean;
|
|
66
66
|
/**
|
|
67
67
|
* Sets readonly property on given objects
|
|
68
68
|
* @param objs array of given objects or a single object
|
|
@@ -355,30 +355,37 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
355
355
|
* Apply the changes and empty the delta object
|
|
356
356
|
*/
|
|
357
357
|
function apply_changes() {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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;
|
|
373
|
+
} finally {
|
|
374
|
+
this.clear_changes();
|
|
362
375
|
}
|
|
363
|
-
if (!this.isChanged) {
|
|
364
|
-
console.warn("No changes to apply");
|
|
365
|
-
}
|
|
366
|
-
for (var key in this.__delta) {
|
|
367
|
-
var nv = this.__delta[key];
|
|
368
|
-
this[key] = nv;
|
|
369
|
-
}
|
|
370
|
-
this.clear_changes();
|
|
371
376
|
}
|
|
372
377
|
}, {
|
|
373
378
|
key: "clear_changes",
|
|
374
379
|
value: function clear_changes() {
|
|
375
380
|
this.__delta = {};
|
|
376
381
|
this.__changed = false;
|
|
382
|
+
return true;
|
|
377
383
|
}
|
|
378
384
|
}, {
|
|
379
385
|
key: "clear_cache",
|
|
380
386
|
value: function clear_cache() {
|
|
381
387
|
this.__temp = {};
|
|
388
|
+
return true;
|
|
382
389
|
}
|
|
383
390
|
/**
|
|
384
391
|
* Sets readonly property on given objects
|
|
@@ -393,23 +400,28 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
|
|
|
393
400
|
/* -------------------------------------------------------------------------- */
|
|
394
401
|
function get() {
|
|
395
402
|
var _this2 = this;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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;
|
|
412
423
|
}
|
|
424
|
+
return false;
|
|
413
425
|
}
|
|
414
426
|
return false;
|
|
415
427
|
}
|
|
@@ -814,7 +826,8 @@ function _getSubProperty2(key, subkey) {
|
|
|
814
826
|
return subobj[subkey];
|
|
815
827
|
}
|
|
816
828
|
function _setProperty2(key, value) {
|
|
817
|
-
|
|
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
|
|
818
831
|
return true;
|
|
819
832
|
}
|
|
820
833
|
function _setDefaultProperty2(key, value) {
|