@azrico/webobject 1.3.14 → 1.3.16

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.
@@ -410,9 +410,10 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
410
410
  value: function () {
411
411
  var _onSave = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
412
412
  var _this3 = this,
413
- _this$manager3;
413
+ _this$manager4;
414
414
  var srObject,
415
415
  actual_sr,
416
+ _this$manager3,
416
417
  _len3,
417
418
  p,
418
419
  _key3,
@@ -420,36 +421,45 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
420
421
  return _regeneratorRuntime().wrap(function _callee8$(_context8) {
421
422
  while (1) switch (_context8.prev = _context8.next) {
422
423
  case 0:
423
- if (this.isSaved) {
424
- this.apply_changes();
425
- srObject = this.getSaveResult(true);
426
- if (srObject != null) {
427
- //we may have some extra data in the save result.
428
- //try to find the main data
429
- if (Array.isArray(srObject)) {
430
- actual_sr = srObject.find(function (s) {
431
- return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
432
- });
433
- if (actual_sr) srObject = actual_sr;
434
- }
435
- if (_classPrivateMethodGet(this, _isValidSR, _isValidSR2).call(this, srObject)) {
436
- if (srObject.insertedId || srObject._id) {
437
- this._id = srObject.insertedId || srObject._id;
438
- }
439
- if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
440
- this._index_value = Number(srObject._index_value);
441
- }
442
- }
443
- }
424
+ if (!this.isSaved) {
425
+ _context8.next = 10;
426
+ break;
427
+ }
428
+ this.apply_changes();
429
+ srObject = this.getSaveResult(true);
430
+ if (!(srObject != null)) {
431
+ _context8.next = 10;
432
+ break;
433
+ }
434
+ //we may have some extra data in the save result.
435
+ //try to find the main data
436
+ if (Array.isArray(srObject)) {
437
+ actual_sr = srObject.find(function (s) {
438
+ return _classPrivateMethodGet(_this3, _isValidSR, _isValidSR2).call(_this3, s);
439
+ });
440
+ if (actual_sr) srObject = actual_sr;
444
441
  }
442
+ if (!_classPrivateMethodGet(this, _isValidSR, _isValidSR2).call(this, srObject)) {
443
+ _context8.next = 10;
444
+ break;
445
+ }
446
+ if (srObject.insertedId || srObject._id) {
447
+ this._id = srObject.insertedId || srObject._id;
448
+ }
449
+ if (srObject._index_value && !Number.isNaN(srObject._index_value)) {
450
+ this._index_value = Number(srObject._index_value);
451
+ }
452
+ _context8.next = 10;
453
+ return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.event_run("on_id_change");
454
+ case 10:
445
455
  for (_len3 = _args8.length, p = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
446
456
  p[_key3] = _args8[_key3];
447
457
  }
448
- _context8.next = 4;
449
- return (_this$manager3 = this.manager) === null || _this$manager3 === void 0 ? void 0 : _this$manager3.onSave.apply(_this$manager3, p);
450
- case 4:
458
+ _context8.next = 13;
459
+ return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onSave.apply(_this$manager4, p);
460
+ case 13:
451
461
  return _context8.abrupt("return", _context8.sent);
452
- case 5:
462
+ case 14:
453
463
  case "end":
454
464
  return _context8.stop();
455
465
  }
@@ -464,7 +474,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
464
474
  key: "onNew",
465
475
  value: function () {
466
476
  var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
467
- var _this$manager4;
477
+ var _this$manager5;
468
478
  var _len4,
469
479
  p,
470
480
  _key4,
@@ -476,7 +486,7 @@ var WebObject = /*#__PURE__*/function (_SimpleObject) {
476
486
  p[_key4] = _args9[_key4];
477
487
  }
478
488
  _context9.next = 3;
479
- return (_this$manager4 = this.manager) === null || _this$manager4 === void 0 ? void 0 : _this$manager4.onNew.apply(_this$manager4, p);
489
+ return (_this$manager5 = this.manager) === null || _this$manager5 === void 0 ? void 0 : _this$manager5.onNew.apply(_this$manager5, p);
480
490
  case 3:
481
491
  return _context9.abrupt("return", _context9.sent);
482
492
  case 4:
@@ -315,10 +315,13 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
315
315
  return this.event_run("on_after_load");
316
316
  case 7:
317
317
  _context7.next = 9;
318
- return Promise.resolve(true);
318
+ return this.event_run("on_load_finished");
319
319
  case 9:
320
+ _context7.next = 11;
321
+ return Promise.resolve(true);
322
+ case 11:
320
323
  return _context7.abrupt("return", _context7.sent);
321
- case 10:
324
+ case 12:
322
325
  case "end":
323
326
  return _context7.stop();
324
327
  }
@@ -351,10 +354,13 @@ var WebObjectManager = /*#__PURE__*/function (_ObjectManager) {
351
354
  return this.event_run("on_after_save");
352
355
  case 6:
353
356
  _context8.next = 8;
354
- return Promise.resolve(true);
357
+ return this.event_run("on_save_finished");
355
358
  case 8:
359
+ _context8.next = 10;
360
+ return Promise.resolve(true);
361
+ case 10:
356
362
  return _context8.abrupt("return", _context8.sent);
357
- case 9:
363
+ case 11:
358
364
  case "end":
359
365
  return _context8.stop();
360
366
  }
@@ -64,24 +64,12 @@ export declare class SimpleObject extends MapableObject {
64
64
  * set the value to its original
65
65
  * @param key
66
66
  */
67
- resetValue(key: WriteablePropOf<this>): Promise<boolean>;
67
+ reset(key: WriteablePropOf<this>, notifyChanged?: sendChangesType): Promise<boolean>;
68
68
  /**
69
- * set the value to its original
70
- * @param key
71
- */
72
- reset: (key: WriteablePropOf<this>) => Promise<boolean>;
73
- /**
74
- * clear any changes related to the key
75
- * only works in when useDelta is true
76
- * @param key
77
- */
78
- clearDeltaValue(key: WriteablePropOf<this>): boolean;
79
- /**
80
- * clear any changes related to the key
81
- * only works in when useDelta is true
69
+ * reset all values back to their original
82
70
  * @param key
83
71
  */
84
- clear: (key: WriteablePropOf<this>) => boolean;
72
+ resetAll(notifyChanged?: sendChangesType): Promise<boolean>;
85
73
  /**
86
74
  * set key of subObject
87
75
  * @param key
@@ -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,7 +63,6 @@ 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);
@@ -107,17 +105,6 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
107
105
  * @returns
108
106
  */
109
107
  _defineProperty(_assertThisInitialized(_this), "setDefault", _this.setDefaultValue);
110
- /**
111
- * set the value to its original
112
- * @param key
113
- */
114
- _defineProperty(_assertThisInitialized(_this), "reset", _this.resetValue);
115
- /**
116
- * clear any changes related to the key
117
- * only works in when useDelta is true
118
- * @param key
119
- */
120
- _defineProperty(_assertThisInitialized(_this), "clear", _this.clearDeltaValue);
121
108
  _defineProperty(_assertThisInitialized(_this), "get_managerClass", function () {
122
109
  return null;
123
110
  });
@@ -223,29 +210,85 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
223
210
  return _classPrivateMethodGet(this, _setDefaultProperty, _setDefaultProperty2).call(this, key, value);
224
211
  }
225
212
  }, {
226
- key: "resetValue",
213
+ key: "reset",
227
214
  value:
228
215
  /**
229
216
  * set the value to its original
230
217
  * @param key
231
218
  */
232
- function resetValue(key) {
233
- return this.setValue(key, _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key, true));
234
- }
235
- }, {
236
- key: "clearDeltaValue",
237
- value:
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
+ }()
238
242
  /**
239
- * clear any changes related to the key
240
- * only works in when useDelta is true
243
+ * reset all values back to their original
241
244
  * @param key
242
245
  */
243
- function clearDeltaValue(key) {
244
- return _classPrivateMethodGet(this, _clearDeltaProperty, _clearDeltaProperty2).call(this, key);
245
- }
246
246
  }, {
247
- key: "setSubValue",
248
- value:
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
+ }()
249
292
  /**
250
293
  * set key of subObject
251
294
  * @param key
@@ -253,30 +296,32 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
253
296
  * @param subvalue
254
297
  * @return true if changed , false otherwise
255
298
  */
256
- function () {
257
- 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) {
258
303
  var sendChanges,
259
304
  isValueChanged,
260
305
  subval,
261
- _args2 = arguments;
262
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
263
- 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) {
264
309
  case 0:
265
- sendChanges = _args2.length > 3 && _args2[3] !== undefined ? _args2[3] : "auto";
310
+ sendChanges = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : "auto";
266
311
  if (this.canModify) {
267
- _context2.next = 7;
312
+ _context4.next = 7;
268
313
  break;
269
314
  }
270
315
  if (!(this.__throw_errors !== false)) {
271
- _context2.next = 6;
316
+ _context4.next = 6;
272
317
  break;
273
318
  }
274
319
  throw Error("Cant use setValue when on readonly mode");
275
320
  case 6:
276
- return _context2.abrupt("return", false);
321
+ return _context4.abrupt("return", false);
277
322
  case 7:
278
323
  isValueChanged = false;
279
- _context2.prev = 8;
324
+ _context4.prev = 8;
280
325
  //if accessing subval of an object, make sure the object is not null
281
326
  subval = _classPrivateMethodGet(this, _getSubProperty, _getSubProperty2).call(this, key, objKey);
282
327
  if (!(0, _object.object_equals)(subval, subvalue, {
@@ -286,24 +331,24 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
286
331
  isValueChanged = true;
287
332
  } else isValueChanged = false;
288
333
  case 11:
289
- _context2.prev = 11;
334
+ _context4.prev = 11;
290
335
  if (!(sendChanges === true || sendChanges === "auto" && isValueChanged)) {
291
- _context2.next = 15;
336
+ _context4.next = 15;
292
337
  break;
293
338
  }
294
- _context2.next = 15;
339
+ _context4.next = 15;
295
340
  return this.notifyChanged("", String(key), objKey, subvalue);
296
341
  case 15:
297
- return _context2.finish(11);
342
+ return _context4.finish(11);
298
343
  case 16:
299
- return _context2.abrupt("return", isValueChanged);
344
+ return _context4.abrupt("return", isValueChanged);
300
345
  case 17:
301
346
  case "end":
302
- return _context2.stop();
347
+ return _context4.stop();
303
348
  }
304
- }, _callee2, this, [[8,, 11, 16]]);
349
+ }, _callee4, this, [[8,, 11, 16]]);
305
350
  }));
306
- function setSubValue(_x3, _x4, _x5) {
351
+ function setSubValue(_x4, _x5, _x6) {
307
352
  return _setSubValue.apply(this, arguments);
308
353
  }
309
354
  return setSubValue;
@@ -318,64 +363,64 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
318
363
  }, {
319
364
  key: "pushValue",
320
365
  value: function () {
321
- var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key, value) {
366
+ var _pushValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key, value) {
322
367
  var sendChanges,
323
368
  tempArray,
324
- _args3 = arguments;
325
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
326
- 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) {
327
372
  case 0:
328
- sendChanges = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : "auto";
373
+ sendChanges = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : "auto";
329
374
  if (!(value == null)) {
330
- _context3.next = 3;
375
+ _context5.next = 3;
331
376
  break;
332
377
  }
333
- return _context3.abrupt("return", false);
378
+ return _context5.abrupt("return", false);
334
379
  case 3:
335
380
  if (this.canModify) {
336
- _context3.next = 9;
381
+ _context5.next = 9;
337
382
  break;
338
383
  }
339
384
  if (!(this.__throw_errors !== false)) {
340
- _context3.next = 8;
385
+ _context5.next = 8;
341
386
  break;
342
387
  }
343
388
  throw Error("Cant use pushValue when on readonly mode");
344
389
  case 8:
345
- return _context3.abrupt("return", false);
390
+ return _context5.abrupt("return", false);
346
391
  case 9:
347
392
  if (_classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key) == null) {
348
393
  _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, []);
349
394
  }
350
395
  tempArray = _classPrivateMethodGet(this, _getProperty, _getProperty2).call(this, key);
351
396
  if (Array.isArray(tempArray)) {
352
- _context3.next = 17;
397
+ _context5.next = 17;
353
398
  break;
354
399
  }
355
400
  if (!(this.__throw_errors !== false)) {
356
- _context3.next = 16;
401
+ _context5.next = 16;
357
402
  break;
358
403
  }
359
404
  throw Error("Cant use pushValue on non Array keys");
360
405
  case 16:
361
- return _context3.abrupt("return", false);
406
+ return _context5.abrupt("return", false);
362
407
  case 17:
363
408
  _classPrivateMethodGet(this, _setProperty, _setProperty2).call(this, key, [].concat(_toConsumableArray(tempArray), [value]));
364
409
  if (!(sendChanges === true || sendChanges === "auto")) {
365
- _context3.next = 21;
410
+ _context5.next = 21;
366
411
  break;
367
412
  }
368
- _context3.next = 21;
413
+ _context5.next = 21;
369
414
  return this.notifyChanged("", String(key), value);
370
415
  case 21:
371
- return _context3.abrupt("return", tempArray);
416
+ return _context5.abrupt("return", tempArray);
372
417
  case 22:
373
418
  case "end":
374
- return _context3.stop();
419
+ return _context5.stop();
375
420
  }
376
- }, _callee3, this);
421
+ }, _callee5, this);
377
422
  }));
378
- function pushValue(_x6, _x7) {
423
+ function pushValue(_x7, _x8) {
379
424
  return _pushValue.apply(this, arguments);
380
425
  }
381
426
  return pushValue;
@@ -390,10 +435,10 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
390
435
  }, {
391
436
  key: "notifyChanged",
392
437
  value: function () {
393
- 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) {
394
439
  var lc, manager_class;
395
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
396
- while (1) switch (_context4.prev = _context4.next) {
440
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
441
+ while (1) switch (_context6.prev = _context6.next) {
397
442
  case 0:
398
443
  if (value === undefined && type != "meta") value = this.getValue(key);
399
444
  this.__changed = true;
@@ -408,18 +453,18 @@ var SimpleObject = /*#__PURE__*/function (_MapableObject) {
408
453
  /* --------------------------- notify the manager --------------------------- */
409
454
  manager_class = this.get_managerClass();
410
455
  if (!(manager_class instanceof _ObjectManager["default"])) {
411
- _context4.next = 10;
456
+ _context6.next = 10;
412
457
  break;
413
458
  }
414
- _context4.next = 10;
459
+ _context6.next = 10;
415
460
  return manager_class.notifyChanged(type, key, value, subvalue);
416
461
  case 10:
417
462
  case "end":
418
- return _context4.stop();
463
+ return _context6.stop();
419
464
  }
420
- }, _callee4, this);
465
+ }, _callee6, this);
421
466
  }));
422
- function notifyChanged(_x8, _x9, _x10, _x11) {
467
+ function notifyChanged(_x9, _x10, _x11, _x12) {
423
468
  return _notifyChanged.apply(this, arguments);
424
469
  }
425
470
  return notifyChanged;
@@ -934,13 +979,6 @@ function _setProperty2(key, value) {
934
979
  return true;
935
980
  }
936
981
  }
937
- function _clearDeltaProperty2(key) {
938
- if (this.__use_delta) {
939
- delete this.__delta[key];
940
- return true;
941
- }
942
- return false;
943
- }
944
982
  function _setDefaultProperty2(key, value) {
945
983
  //@ts-ignore
946
984
  if (this[key] == undefined || this[key] === "" || this[key] === 0) {
@@ -952,11 +990,9 @@ function _setDefaultProperty2(key, value) {
952
990
  function _getProperty2(key) {
953
991
  var original = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
954
992
  //check if we should use delta version or normal version for this property
955
- if (this.__use_delta && !original && key in this.__delta) {
956
- //@ts-ignore
957
- return this.__delta[key];
958
- }
959
- return this[key];
993
+ if (original || !this.__use_delta || !(key in this.__delta)) return this[key];
994
+ //@ts-ignore
995
+ return this.__delta[key];
960
996
  }
961
997
  function _getTempProperty2(key) {
962
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.14",
3
+ "version": "1.3.16",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",