@azrico/webobject 1.3.13 → 1.3.15

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.
@@ -75,10 +75,10 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
75
75
  var createIfNotExists = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
76
76
  var sendChange = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "auto";
77
77
  if (!this.canModify) {
78
- if (this.__throw_errors) throw Error("Cant use setMetaValue on ".concat(key, " when on readonly mode"));else return false;
78
+ if (this.__throw_errors !== false) throw Error("Cant use setMetaValue on ".concat(key, " when on readonly mode"));else return false;
79
79
  }
80
80
  if (!key || typeof key != "string") {
81
- if (this.__throw_errors) throw Error("Bad key at setMetaValue");else return false;
81
+ if (this.__throw_errors !== false) throw Error("Bad key at setMetaValue");else return false;
82
82
  }
83
83
  var old_value = WebObject.getMetaValue(this, key);
84
84
  if ((0, _object.object_equals)(old_value, value)) return false; //same value, no changes
@@ -127,7 +127,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
127
127
  return _regeneratorRuntime().wrap(function _callee$(_context) {
128
128
  while (1) switch (_context.prev = _context.next) {
129
129
  case 0:
130
- if (!this.__throw_errors) {
130
+ if (!(this.__throw_errors !== false)) {
131
131
  _context.next = 2;
132
132
  break;
133
133
  }
@@ -154,7 +154,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
154
154
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
155
155
  while (1) switch (_context2.prev = _context2.next) {
156
156
  case 0:
157
- if (!this.__throw_errors) {
157
+ if (!(this.__throw_errors !== false)) {
158
158
  _context2.next = 2;
159
159
  break;
160
160
  }
@@ -18,10 +18,10 @@ export declare class SimpleObject extends MapableObject {
18
18
  __delta: Partial<this>;
19
19
  __temp: any;
20
20
  __changed: boolean;
21
- __lastChanged: string;
22
- __is_readonly: boolean;
23
- __throw_errors: boolean;
24
- _deleted: boolean;
21
+ __lastChanged?: string;
22
+ __is_readonly?: boolean;
23
+ __throw_errors?: boolean;
24
+ _deleted?: boolean;
25
25
  _deletedBy?: string;
26
26
  __errors?: any[];
27
27
  __showErrors?: boolean;
@@ -46,10 +46,30 @@ export declare class SimpleObject extends MapableObject {
46
46
  setValue(key: WriteablePropOf<this>, value: any, sendChanges?: sendChangesType): Promise<boolean>;
47
47
  set: (key: WriteablePropOf<this>, value: any, sendChanges?: sendChangesType) => Promise<boolean>;
48
48
  setTemp: (key: string, value: any) => any;
49
+ /**
50
+ * set value of a key only if the value is empty
51
+ * @param key
52
+ * @param value
53
+ * @returns
54
+ */
49
55
  setDefaultValue(key: WriteablePropOf<this>, value: any): boolean;
56
+ /**
57
+ * set value of a key only if the value is empty
58
+ * @param key
59
+ * @param value
60
+ * @returns
61
+ */
50
62
  setDefault: (key: WriteablePropOf<this>, value: any) => boolean;
51
- clearDeltaValue(key: WriteablePropOf<this>): boolean;
52
- clear: (key: WriteablePropOf<this>) => boolean;
63
+ /**
64
+ * set the value to its original
65
+ * @param key
66
+ */
67
+ reset(key: WriteablePropOf<this>, notifyChanged?: sendChangesType): Promise<boolean>;
68
+ /**
69
+ * reset all values back to their original
70
+ * @param key
71
+ */
72
+ resetAll(notifyChanged?: sendChangesType): Promise<boolean>;
53
73
  /**
54
74
  * set key of subObject
55
75
  * @param key
@@ -58,14 +78,43 @@ export declare class SimpleObject extends MapableObject {
58
78
  * @return true if changed , false otherwise
59
79
  */
60
80
  setSubValue(key: PropOf<this>, objKey: string, subvalue: any, sendChanges?: sendChangesType): Promise<boolean>;
81
+ /**
82
+ * Push value on array
83
+ * @param key
84
+ * @param value
85
+ * @param sendChanges
86
+ * @returns
87
+ */
61
88
  pushValue<MKey extends PropOf<this>>(key: MKey, value: any, sendChanges?: sendChangesType): Promise<this[MKey] | false>;
89
+ /**
90
+ * notify the manager class when a value is changed on this object
91
+ * @param type
92
+ * @param key
93
+ * @param value
94
+ * @param subvalue
95
+ */
62
96
  notifyChanged(type: string, key: string, value: any, subvalue?: any): Promise<void>;
97
+ /**
98
+ * check if a key can be changed on an object
99
+ * @param object
100
+ * @param key
101
+ * @param useExtraProps
102
+ * @returns
103
+ */
63
104
  static canChangeKey(object: SimpleObject, key: string, useExtraProps: boolean): boolean;
64
105
  /**
65
106
  * Apply the changes and empty the delta object
66
107
  */
67
108
  apply_changes(): boolean;
109
+ /**
110
+ * clear and discard all changes
111
+ * @returns
112
+ */
68
113
  clear_changes(): boolean;
114
+ /**
115
+ * clear and discard all temp values
116
+ * @returns
117
+ */
69
118
  clear_cache(): boolean;
70
119
  /**
71
120
  * Sets readonly property on given objects
@@ -41,7 +41,6 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
41
41
  var _setSubProperty = /*#__PURE__*/new WeakSet();
42
42
  var _getSubProperty = /*#__PURE__*/new WeakSet();
43
43
  var _setProperty = /*#__PURE__*/new WeakSet();
44
- var _clearDeltaProperty = /*#__PURE__*/new WeakSet();
45
44
  var _setDefaultProperty = /*#__PURE__*/new WeakSet();
46
45
  var _getProperty = /*#__PURE__*/new WeakSet();
47
46
  var _getTempProperty = /*#__PURE__*/new WeakSet();
@@ -64,20 +63,24 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
64
63
  _classPrivateMethodInitSpec(_assertThisInitialized(_this), _getTempProperty);
65
64
  _classPrivateMethodInitSpec(_assertThisInitialized(_this), _getProperty);
66
65
  _classPrivateMethodInitSpec(_assertThisInitialized(_this), _setDefaultProperty);
67
- _classPrivateMethodInitSpec(_assertThisInitialized(_this), _clearDeltaProperty);
68
66
  _classPrivateMethodInitSpec(_assertThisInitialized(_this), _setProperty);
69
67
  _classPrivateMethodInitSpec(_assertThisInitialized(_this), _getSubProperty);
70
68
  _classPrivateMethodInitSpec(_assertThisInitialized(_this), _setSubProperty);
69
+ //an exact copy of this object is stored here
71
70
  _defineProperty(_assertThisInitialized(_this), "__originalobject", void 0);
72
- //changes
71
+ //changes are saved here
73
72
  _defineProperty(_assertThisInitialized(_this), "__delta", {});
74
73
  _defineProperty(_assertThisInitialized(_this), "__temp", undefined);
75
74
  _defineProperty(_assertThisInitialized(_this), "__changed", false);
76
- _defineProperty(_assertThisInitialized(_this), "__lastChanged", "");
75
+ //the last thing that was changed on this object
76
+ _defineProperty(_assertThisInitialized(_this), "__lastChanged", void 0);
77
+ //is the object read only
77
78
  _defineProperty(_assertThisInitialized(_this), "__is_readonly", void 0);
79
+ //should we throw errors when encountering an error?
80
+ //is TRUE by default
78
81
  _defineProperty(_assertThisInitialized(_this), "__throw_errors", void 0);
79
82
  //is this object marked as deleted?
80
- _defineProperty(_assertThisInitialized(_this), "_deleted", false);
83
+ _defineProperty(_assertThisInitialized(_this), "_deleted", void 0);
81
84
  _defineProperty(_assertThisInitialized(_this), "_deletedBy", void 0);
82
85
  //errors
83
86
  _defineProperty(_assertThisInitialized(_this), "__errors", void 0);
@@ -86,7 +89,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
86
89
  _defineProperty(_assertThisInitialized(_this), "__saveResultObject", void 0);
87
90
  _defineProperty(_assertThisInitialized(_this), "__saveResultIsSuccess", true);
88
91
  _defineProperty(_assertThisInitialized(_this), "__saveResultType", void 0);
89
- //sequence key
92
+ //sequence key (usually managed by the database)
90
93
  _defineProperty(_assertThisInitialized(_this), "_index_key", "");
91
94
  //sequence value , used to index the object with increasing numbers
92
95
  _defineProperty(_assertThisInitialized(_this), "_index_value", -1);
@@ -95,14 +98,17 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
95
98
  _defineProperty(_assertThisInitialized(_this), "getTemp", _classPrivateMethodGet(_assertThisInitialized(_this), _getTempProperty, _getTempProperty2));
96
99
  _defineProperty(_assertThisInitialized(_this), "set", _this.setValue);
97
100
  _defineProperty(_assertThisInitialized(_this), "setTemp", _classPrivateMethodGet(_assertThisInitialized(_this), _setTempProperty, _setTempProperty2));
101
+ /**
102
+ * set value of a key only if the value is empty
103
+ * @param key
104
+ * @param value
105
+ * @returns
106
+ */
98
107
  _defineProperty(_assertThisInitialized(_this), "setDefault", _this.setDefaultValue);
99
- _defineProperty(_assertThisInitialized(_this), "clear", _this.clearDeltaValue);
100
108
  _defineProperty(_assertThisInitialized(_this), "get_managerClass", function () {
101
109
  return null;
102
110
  });
103
- if (_this._deleted == null) _this._deleted = false;
104
111
  _this.__is_readonly = is_readonly;
105
- _this.__throw_errors = true;
106
112
  _this.clear_changes();
107
113
  return _this;
108
114
  }
@@ -150,7 +156,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
150
156
  _context.next = 7;
151
157
  break;
152
158
  }
153
- if (!this.__throw_errors) {
159
+ if (!(this.__throw_errors !== false)) {
154
160
  _context.next = 6;
155
161
  break;
156
162
  }
@@ -193,17 +199,96 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
193
199
  }()
194
200
  }, {
195
201
  key: "setDefaultValue",
196
- value: function setDefaultValue(key, value) {
202
+ value:
203
+ /**
204
+ * set value of a key only if the value is empty
205
+ * @param key
206
+ * @param value
207
+ * @returns
208
+ */
209
+ function setDefaultValue(key, value) {
197
210
  return _classPrivateMethodGet(this, _setDefaultProperty, _setDefaultProperty2).call(this, key, value);
198
211
  }
199
212
  }, {
200
- key: "clearDeltaValue",
201
- value: function clearDeltaValue(key) {
202
- return _classPrivateMethodGet(this, _clearDeltaProperty, _clearDeltaProperty2).call(this, key);
203
- }
204
- }, {
205
- key: "setSubValue",
213
+ key: "reset",
206
214
  value:
215
+ /**
216
+ * set the value to its original
217
+ * @param key
218
+ */
219
+ function () {
220
+ var _reset = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key) {
221
+ var notifyChanged,
222
+ _args2 = arguments;
223
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
224
+ while (1) switch (_context2.prev = _context2.next) {
225
+ case 0:
226
+ notifyChanged = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : "auto";
227
+ _context2.next = 3;
228
+ return this.setValue(key, this[key], notifyChanged);
229
+ case 3:
230
+ return _context2.abrupt("return", _context2.sent);
231
+ case 4:
232
+ case "end":
233
+ return _context2.stop();
234
+ }
235
+ }, _callee2, this);
236
+ }));
237
+ function reset(_x3) {
238
+ return _reset.apply(this, arguments);
239
+ }
240
+ return reset;
241
+ }()
242
+ /**
243
+ * reset all values back to their original
244
+ * @param key
245
+ */
246
+ }, {
247
+ key: "resetAll",
248
+ value: function () {
249
+ var _resetAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
250
+ var notifyChanged,
251
+ fr,
252
+ key,
253
+ _args3 = arguments;
254
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
255
+ while (1) switch (_context3.prev = _context3.next) {
256
+ case 0:
257
+ notifyChanged = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : "auto";
258
+ fr = true;
259
+ _context3.t0 = _regeneratorRuntime().keys(this.__delta);
260
+ case 3:
261
+ if ((_context3.t1 = _context3.t0()).done) {
262
+ _context3.next = 13;
263
+ break;
264
+ }
265
+ key = _context3.t1.value;
266
+ _context3.t2 = fr;
267
+ if (!_context3.t2) {
268
+ _context3.next = 10;
269
+ break;
270
+ }
271
+ _context3.next = 9;
272
+ return this.reset(key, notifyChanged);
273
+ case 9:
274
+ _context3.t2 = _context3.sent;
275
+ case 10:
276
+ fr = _context3.t2;
277
+ _context3.next = 3;
278
+ break;
279
+ case 13:
280
+ return _context3.abrupt("return", fr);
281
+ case 14:
282
+ case "end":
283
+ return _context3.stop();
284
+ }
285
+ }, _callee3, this);
286
+ }));
287
+ function resetAll() {
288
+ return _resetAll.apply(this, arguments);
289
+ }
290
+ return resetAll;
291
+ }()
207
292
  /**
208
293
  * set key of subObject
209
294
  * @param key
@@ -211,30 +296,32 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
211
296
  * @param subvalue
212
297
  * @return true if changed , false otherwise
213
298
  */
214
- function () {
215
- var _setSubValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, objKey, subvalue) {
299
+ }, {
300
+ key: "setSubValue",
301
+ value: function () {
302
+ var _setSubValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key, objKey, subvalue) {
216
303
  var sendChanges,
217
304
  isValueChanged,
218
305
  subval,
219
- _args2 = arguments;
220
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
221
- while (1) switch (_context2.prev = _context2.next) {
306
+ _args4 = arguments;
307
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
308
+ while (1) switch (_context4.prev = _context4.next) {
222
309
  case 0:
223
- sendChanges = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : "auto";
310
+ sendChanges = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : "auto";
224
311
  if (this.canModify) {
225
- _context2.next = 7;
312
+ _context4.next = 7;
226
313
  break;
227
314
  }
228
- if (!this.__throw_errors) {
229
- _context2.next = 6;
315
+ if (!(this.__throw_errors !== false)) {
316
+ _context4.next = 6;
230
317
  break;
231
318
  }
232
319
  throw Error("Cant use setValue when on readonly mode");
233
320
  case 6:
234
- return _context2.abrupt("return", false);
321
+ return _context4.abrupt("return", false);
235
322
  case 7:
236
323
  isValueChanged = false;
237
- _context2.prev = 8;
324
+ _context4.prev = 8;
238
325
  //if accessing subval of an object, make sure the object is not null
239
326
  subval = _classPrivateMethodGet(this, _getSubProperty, _getSubProperty2).call(this, key, objKey);
240
327
  if (!(0, _object.object_equals)(subval, subvalue, {
@@ -244,100 +331,114 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
244
331
  isValueChanged = true;
245
332
  } else isValueChanged = false;
246
333
  case 11:
247
- _context2.prev = 11;
334
+ _context4.prev = 11;
248
335
  if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
249
- _context2.next = 15;
336
+ _context4.next = 15;
250
337
  break;
251
338
  }
252
- _context2.next = 15;
339
+ _context4.next = 15;
253
340
  return this.notifyChanged("", String(key), objKey, subvalue);
254
341
  case 15:
255
- return _context2.finish(11);
342
+ return _context4.finish(11);
256
343
  case 16:
257
- return _context2.abrupt("return", isValueChanged);
344
+ return _context4.abrupt("return", isValueChanged);
258
345
  case 17:
259
346
  case "end":
260
- return _context2.stop();
347
+ return _context4.stop();
261
348
  }
262
- }, _callee2, this, [[8,, 11, 16]]);
349
+ }, _callee4, this, [[8,, 11, 16]]);
263
350
  }));
264
- function setSubValue(_x3, _x4, _x5) {
351
+ function setSubValue(_x4, _x5, _x6) {
265
352
  return _setSubValue.apply(this, arguments);
266
353
  }
267
354
  return setSubValue;
268
- }() //Push value on array
355
+ }()
356
+ /**
357
+ * Push value on array
358
+ * @param key
359
+ * @param value
360
+ * @param sendChanges
361
+ * @returns
362
+ */
269
363
  }, {
270
364
  key: "pushValue",
271
365
  value: function () {
272
- var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, value) {
366
+ var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key, value) {
273
367
  var sendChanges,
274
368
  tempArray,
275
- _args3 = arguments;
276
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
277
- while (1) switch (_context3.prev = _context3.next) {
369
+ _args5 = arguments;
370
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
371
+ while (1) switch (_context5.prev = _context5.next) {
278
372
  case 0:
279
- sendChanges = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : "auto";
373
+ sendChanges = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : "auto";
280
374
  if (!(value == null)) {
281
- _context3.next = 3;
375
+ _context5.next = 3;
282
376
  break;
283
377
  }
284
- return _context3.abrupt("return", false);
378
+ return _context5.abrupt("return", false);
285
379
  case 3:
286
380
  if (this.canModify) {
287
- _context3.next = 9;
381
+ _context5.next = 9;
288
382
  break;
289
383
  }
290
- if (!this.__throw_errors) {
291
- _context3.next = 8;
384
+ if (!(this.__throw_errors !== false)) {
385
+ _context5.next = 8;
292
386
  break;
293
387
  }
294
388
  throw Error("Cant use pushValue when on readonly mode");
295
389
  case 8:
296
- return _context3.abrupt("return", false);
390
+ return _context5.abrupt("return", false);
297
391
  case 9:
298
392
  if (_classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key) == null) {
299
393
  _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, []);
300
394
  }
301
395
  tempArray = _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key);
302
396
  if (Array.isArray(tempArray)) {
303
- _context3.next = 17;
397
+ _context5.next = 17;
304
398
  break;
305
399
  }
306
- if (!this.__throw_errors) {
307
- _context3.next = 16;
400
+ if (!(this.__throw_errors !== false)) {
401
+ _context5.next = 16;
308
402
  break;
309
403
  }
310
404
  throw Error("Cant use pushValue on non Array keys");
311
405
  case 16:
312
- return _context3.abrupt("return", false);
406
+ return _context5.abrupt("return", false);
313
407
  case 17:
314
408
  _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, [].concat(_toConsumableArray(tempArray), [value]));
315
409
  if (!(sendChanges === true || sendChanges === "auto")) {
316
- _context3.next = 21;
410
+ _context5.next = 21;
317
411
  break;
318
412
  }
319
- _context3.next = 21;
413
+ _context5.next = 21;
320
414
  return this.notifyChanged("", String(key), value);
321
415
  case 21:
322
- return _context3.abrupt("return", tempArray);
416
+ return _context5.abrupt("return", tempArray);
323
417
  case 22:
324
418
  case "end":
325
- return _context3.stop();
419
+ return _context5.stop();
326
420
  }
327
- }, _callee3, this);
421
+ }, _callee5, this);
328
422
  }));
329
- function pushValue(_x6, _x7) {
423
+ function pushValue(_x7, _x8) {
330
424
  return _pushValue.apply(this, arguments);
331
425
  }
332
426
  return pushValue;
333
427
  }()
428
+ /**
429
+ * notify the manager class when a value is changed on this object
430
+ * @param type
431
+ * @param key
432
+ * @param value
433
+ * @param subvalue
434
+ */
334
435
  }, {
335
436
  key: "notifyChanged",
336
437
  value: function () {
337
- var _notifyChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(type, key, value, subvalue) {
438
+ var _notifyChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(type, key, value, subvalue) {
338
439
  var lc, manager_class;
339
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
340
- while (1) switch (_context4.prev = _context4.next) {
440
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
441
+ while (1) switch (_context6.prev = _context6.next) {
341
442
  case 0:
342
443
  if (value === undefined && type != "meta") value = this.getValue(key);
343
444
  this.__changed = true;
@@ -352,22 +453,29 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
352
453
  /* --------------------------- notify the manager --------------------------- */
353
454
  manager_class = this.get_managerClass();
354
455
  if (!(manager_class instanceof _ObjectManager["default"])) {
355
- _context4.next = 10;
456
+ _context6.next = 10;
356
457
  break;
357
458
  }
358
- _context4.next = 10;
459
+ _context6.next = 10;
359
460
  return manager_class.notifyChanged(type, key, value, subvalue);
360
461
  case 10:
361
462
  case "end":
362
- return _context4.stop();
463
+ return _context6.stop();
363
464
  }
364
- }, _callee4, this);
465
+ }, _callee6, this);
365
466
  }));
366
- function notifyChanged(_x8, _x9, _x10, _x11) {
467
+ function notifyChanged(_x9, _x10, _x11, _x12) {
367
468
  return _notifyChanged.apply(this, arguments);
368
469
  }
369
470
  return notifyChanged;
370
471
  }()
472
+ /**
473
+ * check if a key can be changed on an object
474
+ * @param object
475
+ * @param key
476
+ * @param useExtraProps
477
+ * @returns
478
+ */
371
479
  }, {
372
480
  key: "apply_changes",
373
481
  value: /* -------------------------------------------------------------------------- */
@@ -396,6 +504,10 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
396
504
  this.clear_changes();
397
505
  }
398
506
  }
507
+ /**
508
+ * clear and discard all changes
509
+ * @returns
510
+ */
399
511
  }, {
400
512
  key: "clear_changes",
401
513
  value: function clear_changes() {
@@ -403,10 +515,14 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
403
515
  this.__changed = false;
404
516
  return true;
405
517
  }
518
+ /**
519
+ * clear and discard all temp values
520
+ * @returns
521
+ */
406
522
  }, {
407
523
  key: "clear_cache",
408
524
  value: function clear_cache() {
409
- this.__temp = undefined;
525
+ delete this.__temp;
410
526
  return true;
411
527
  }
412
528
  /**
@@ -511,7 +627,7 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
511
627
  }, {
512
628
  key: "lastChanged",
513
629
  get: function get() {
514
- return this.__lastChanged;
630
+ return this.__lastChanged || "";
515
631
  }
516
632
  }, {
517
633
  key: "manager",
@@ -851,16 +967,17 @@ function _getSubProperty2(key, subkey) {
851
967
  return subobj[subkey];
852
968
  }
853
969
  function _setProperty2(key, value) {
854
- this.__delta[key] = value; //always update delta to keep track of changes
855
- if (!this.__use_delta) this[key] = value; //on noDelta mode, also update the obj
856
- return true;
857
- }
858
- function _clearDeltaProperty2(key) {
859
- if (this.__use_delta) {
970
+ if (this[key] === value) {
971
+ /**
972
+ * We set something back to its original value so no need to save it as Delta
973
+ */
860
974
  delete this.__delta[key];
975
+ return false;
976
+ } else {
977
+ this.__delta[key] = value; //always update delta to keep track of changes
978
+ if (!this.__use_delta) this[key] = value; //on noDelta mode, also update the obj
861
979
  return true;
862
980
  }
863
- return false;
864
981
  }
865
982
  function _setDefaultProperty2(key, value) {
866
983
  //@ts-ignore
@@ -873,11 +990,9 @@ function _setDefaultProperty2(key, value) {
873
990
  function _getProperty2(key) {
874
991
  var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
875
992
  //check if we should use delta version or normal version for this property
876
- if (this.__use_delta && !original && key in this.__delta) {
877
- //@ts-ignore
878
- return this.__delta[key];
879
- }
880
- return this[key];
993
+ if (original || !this.__use_delta || !(key in this.__delta)) return this[key];
994
+ //@ts-ignore
995
+ return this.__delta[key];
881
996
  }
882
997
  function _getTempProperty2(key) {
883
998
  if (this.__temp == null) return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.3.13",
3
+ "version": "1.3.15",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",