@azrico/webobject 1.5.2 → 1.5.4

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.
@@ -32,12 +32,6 @@ export declare class WebObjectManager<ObjType extends WebObject> extends ObjectM
32
32
  get __object_name(): string;
33
33
  get_webpath(): string;
34
34
  private __getObjectData;
35
- /**
36
- * Use this when you load new Object
37
- * @param p
38
- * @returns
39
- */
40
- onNew(...p: any): Promise<any>;
41
35
  /**
42
36
  * Use this when you delete Object
43
37
  * @param p
@@ -48,6 +42,12 @@ export declare class WebObjectManager<ObjType extends WebObject> extends ObjectM
48
42
  onUnArchive(...p: any): Promise<any>;
49
43
  onLock(...p: any): Promise<any>;
50
44
  onUnLock(...p: any): Promise<any>;
45
+ /**
46
+ * Use this when you load new Object
47
+ * @param p
48
+ * @returns
49
+ */
50
+ onNew(...p: any): Promise<any>;
51
51
  /**
52
52
  * Use this when you load data to the object
53
53
  * @param p
@@ -550,65 +550,51 @@ var WebObjectManager = exports.WebObjectManager = /*#__PURE__*/function (_Object
550
550
  /* Default Events */
551
551
  /* -------------------------------------------------------------------------- */
552
552
  /**
553
- * Use this when you load new Object
553
+ * Use this when you delete Object
554
554
  * @param p
555
555
  * @returns
556
556
  */
557
557
  }, {
558
- key: "onNew",
558
+ key: "onDelete",
559
559
  value: (function () {
560
- var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
561
- var _this$obj11;
560
+ var _onDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
561
+ var srt;
562
562
  return _regeneratorRuntime().wrap(function _callee14$(_context14) {
563
563
  while (1) switch (_context14.prev = _context14.next) {
564
564
  case 0:
565
- if (this.canModify) {
566
- (_this$obj11 = this.obj) === null || _this$obj11 === void 0 || _this$obj11.setOriginal();
567
- }
565
+ srt = this.getSaveResultType();
568
566
  _context14.next = 3;
569
- return this.event_run("on_new");
567
+ return this.event_run("on_delete", srt);
570
568
  case 3:
571
569
  _context14.next = 5;
572
- return this.event_run("on_change", true);
570
+ return this.event_run("on_after_delete", srt);
573
571
  case 5:
574
- _context14.next = 7;
575
- return this.event_run("on_after_new");
576
- case 7:
577
- _context14.next = 9;
578
- return Promise.resolve(true);
579
- case 9:
580
- return _context14.abrupt("return", _context14.sent);
581
- case 10:
572
+ return _context14.abrupt("return", true);
573
+ case 6:
582
574
  case "end":
583
575
  return _context14.stop();
584
576
  }
585
577
  }, _callee14, this);
586
578
  }));
587
- function onNew() {
588
- return _onNew.apply(this, arguments);
579
+ function onDelete() {
580
+ return _onDelete.apply(this, arguments);
589
581
  }
590
- return onNew;
591
- }()
592
- /**
593
- * Use this when you delete Object
594
- * @param p
595
- * @returns
596
- */
597
- )
582
+ return onDelete;
583
+ }())
598
584
  }, {
599
- key: "onDelete",
600
- value: (function () {
601
- var _onDelete = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
585
+ key: "onArchive",
586
+ value: function () {
587
+ var _onArchive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
602
588
  var srt;
603
589
  return _regeneratorRuntime().wrap(function _callee15$(_context15) {
604
590
  while (1) switch (_context15.prev = _context15.next) {
605
591
  case 0:
606
592
  srt = this.getSaveResultType();
607
593
  _context15.next = 3;
608
- return this.event_run("on_delete", srt);
594
+ return this.event_run("on_archive", srt);
609
595
  case 3:
610
596
  _context15.next = 5;
611
- return this.event_run("on_after_delete", srt);
597
+ return this.event_run("on_after_archive", srt);
612
598
  case 5:
613
599
  return _context15.abrupt("return", true);
614
600
  case 6:
@@ -617,25 +603,25 @@ var WebObjectManager = exports.WebObjectManager = /*#__PURE__*/function (_Object
617
603
  }
618
604
  }, _callee15, this);
619
605
  }));
620
- function onDelete() {
621
- return _onDelete.apply(this, arguments);
606
+ function onArchive() {
607
+ return _onArchive.apply(this, arguments);
622
608
  }
623
- return onDelete;
624
- }())
609
+ return onArchive;
610
+ }()
625
611
  }, {
626
- key: "onArchive",
612
+ key: "onUnArchive",
627
613
  value: function () {
628
- var _onArchive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
614
+ var _onUnArchive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
629
615
  var srt;
630
616
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
631
617
  while (1) switch (_context16.prev = _context16.next) {
632
618
  case 0:
633
619
  srt = this.getSaveResultType();
634
620
  _context16.next = 3;
635
- return this.event_run("on_archive", srt);
621
+ return this.event_run("on_unarchive", srt);
636
622
  case 3:
637
623
  _context16.next = 5;
638
- return this.event_run("on_after_archive", srt);
624
+ return this.event_run("on_after_unarchive", srt);
639
625
  case 5:
640
626
  return _context16.abrupt("return", true);
641
627
  case 6:
@@ -644,25 +630,25 @@ var WebObjectManager = exports.WebObjectManager = /*#__PURE__*/function (_Object
644
630
  }
645
631
  }, _callee16, this);
646
632
  }));
647
- function onArchive() {
648
- return _onArchive.apply(this, arguments);
633
+ function onUnArchive() {
634
+ return _onUnArchive.apply(this, arguments);
649
635
  }
650
- return onArchive;
636
+ return onUnArchive;
651
637
  }()
652
638
  }, {
653
- key: "onUnArchive",
639
+ key: "onLock",
654
640
  value: function () {
655
- var _onUnArchive = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
641
+ var _onLock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
656
642
  var srt;
657
643
  return _regeneratorRuntime().wrap(function _callee17$(_context17) {
658
644
  while (1) switch (_context17.prev = _context17.next) {
659
645
  case 0:
660
646
  srt = this.getSaveResultType();
661
647
  _context17.next = 3;
662
- return this.event_run("on_unarchive", srt);
648
+ return this.event_run("on_lock", srt);
663
649
  case 3:
664
650
  _context17.next = 5;
665
- return this.event_run("on_after_unarchive", srt);
651
+ return this.event_run("on_after_lock", srt);
666
652
  case 5:
667
653
  return _context17.abrupt("return", true);
668
654
  case 6:
@@ -671,25 +657,25 @@ var WebObjectManager = exports.WebObjectManager = /*#__PURE__*/function (_Object
671
657
  }
672
658
  }, _callee17, this);
673
659
  }));
674
- function onUnArchive() {
675
- return _onUnArchive.apply(this, arguments);
660
+ function onLock() {
661
+ return _onLock.apply(this, arguments);
676
662
  }
677
- return onUnArchive;
663
+ return onLock;
678
664
  }()
679
665
  }, {
680
- key: "onLock",
666
+ key: "onUnLock",
681
667
  value: function () {
682
- var _onLock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
668
+ var _onUnLock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
683
669
  var srt;
684
670
  return _regeneratorRuntime().wrap(function _callee18$(_context18) {
685
671
  while (1) switch (_context18.prev = _context18.next) {
686
672
  case 0:
687
673
  srt = this.getSaveResultType();
688
674
  _context18.next = 3;
689
- return this.event_run("on_lock", srt);
675
+ return this.event_run("on_unlock", srt);
690
676
  case 3:
691
677
  _context18.next = 5;
692
- return this.event_run("on_after_lock", srt);
678
+ return this.event_run("on_after_unlock", srt);
693
679
  case 5:
694
680
  return _context18.abrupt("return", true);
695
681
  case 6:
@@ -698,43 +684,60 @@ var WebObjectManager = exports.WebObjectManager = /*#__PURE__*/function (_Object
698
684
  }
699
685
  }, _callee18, this);
700
686
  }));
701
- function onLock() {
702
- return _onLock.apply(this, arguments);
687
+ function onUnLock() {
688
+ return _onUnLock.apply(this, arguments);
703
689
  }
704
- return onLock;
690
+ return onUnLock;
705
691
  }()
692
+ /**
693
+ * Use this when you load new Object
694
+ * @param p
695
+ * @returns
696
+ */
706
697
  }, {
707
- key: "onUnLock",
708
- value: function () {
709
- var _onUnLock = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
710
- var srt;
698
+ key: "onNew",
699
+ value: (function () {
700
+ var _onNew = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
701
+ var _this$obj11;
711
702
  return _regeneratorRuntime().wrap(function _callee19$(_context19) {
712
703
  while (1) switch (_context19.prev = _context19.next) {
713
704
  case 0:
714
- srt = this.getSaveResultType();
705
+ if (this.canModify) {
706
+ (_this$obj11 = this.obj) === null || _this$obj11 === void 0 || _this$obj11.setOriginal();
707
+ }
715
708
  _context19.next = 3;
716
- return this.event_run("on_unlock", srt);
709
+ return this.event_run("on_new");
717
710
  case 3:
718
711
  _context19.next = 5;
719
- return this.event_run("on_after_unlock", srt);
712
+ return this.event_run("on_change", true);
720
713
  case 5:
721
- return _context19.abrupt("return", true);
722
- case 6:
714
+ _context19.next = 7;
715
+ return this.event_run("on_after_new");
716
+ case 7:
717
+ _context19.next = 9;
718
+ return this.checkIsChanged();
719
+ case 9:
720
+ _context19.next = 11;
721
+ return Promise.resolve(true);
722
+ case 11:
723
+ return _context19.abrupt("return", _context19.sent);
724
+ case 12:
723
725
  case "end":
724
726
  return _context19.stop();
725
727
  }
726
728
  }, _callee19, this);
727
729
  }));
728
- function onUnLock() {
729
- return _onUnLock.apply(this, arguments);
730
+ function onNew() {
731
+ return _onNew.apply(this, arguments);
730
732
  }
731
- return onUnLock;
733
+ return onNew;
732
734
  }()
733
735
  /**
734
736
  * Use this when you load data to the object
735
737
  * @param p
736
738
  * @returns
737
739
  */
740
+ )
738
741
  }, {
739
742
  key: "onLoad",
740
743
  value: (function () {
@@ -758,8 +761,11 @@ var WebObjectManager = exports.WebObjectManager = /*#__PURE__*/function (_Object
758
761
  _context20.next = 9;
759
762
  return this.event_run("on_load_finished");
760
763
  case 9:
764
+ _context20.next = 11;
765
+ return this.checkIsChanged();
766
+ case 11:
761
767
  return _context20.abrupt("return", true);
762
- case 10:
768
+ case 12:
763
769
  case "end":
764
770
  return _context20.stop();
765
771
  }
@@ -792,10 +798,13 @@ var WebObjectManager = exports.WebObjectManager = /*#__PURE__*/function (_Object
792
798
  return this.event_run("on_change", true);
793
799
  case 5:
794
800
  _context21.next = 7;
795
- return Promise.resolve(true);
801
+ return this.checkIsChanged();
796
802
  case 7:
803
+ _context21.next = 9;
804
+ return Promise.resolve(true);
805
+ case 9:
797
806
  return _context21.abrupt("return", _context21.sent);
798
- case 8:
807
+ case 10:
799
808
  case "end":
800
809
  return _context21.stop();
801
810
  }
@@ -123,10 +123,10 @@ export declare class ObjectManager<ObjType extends SimpleObject> extends RawObje
123
123
  getErrors(): any[];
124
124
  clearErrors(): boolean;
125
125
  /**
126
- *
127
126
  * @returns isChanged
128
127
  */
129
128
  useIsChanged(): any;
129
+ checkIsChanged(): Promise<void>;
130
130
  static addError(o?: ObjectManager<any>, title?: string, message?: string, sendToRegister?: boolean | "auto"): any[] | undefined;
131
131
  static getErrors(o: ObjectManager<any>): any[];
132
132
  static clearErrors(o: ObjectManager<any>): boolean;
@@ -712,18 +712,35 @@ var ObjectManager = exports.ObjectManager = /*#__PURE__*/function (_RawObject) {
712
712
  value: function clearErrors() {
713
713
  return ObjectManager.clearErrors(this);
714
714
  }
715
- /* -------------------------------------------------------------------------- */
715
+ /* ------------------------------ useIsChanged; ----------------------------- */
716
716
  /**
717
- *
718
717
  * @returns isChanged
719
718
  */
720
719
  }, {
721
720
  key: "useIsChanged",
722
721
  value: function useIsChanged() {
723
722
  return this.useOption("ischanged");
724
- //// return this.event_use("on_{change,save,load}", () => this.isChanged);
725
723
  }
726
- /* -------------------------------------------------------------------------- */
724
+ }, {
725
+ key: "checkIsChanged",
726
+ value: function () {
727
+ var _checkIsChanged = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
728
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
729
+ while (1) switch (_context12.prev = _context12.next) {
730
+ case 0:
731
+ _context12.next = 2;
732
+ return this.setOption("ischanged", this.isChanged);
733
+ case 2:
734
+ case "end":
735
+ return _context12.stop();
736
+ }
737
+ }, _callee12, this);
738
+ }));
739
+ function checkIsChanged() {
740
+ return _checkIsChanged.apply(this, arguments);
741
+ }
742
+ return checkIsChanged;
743
+ }()
727
744
  }, {
728
745
  key: "getObjectType",
729
746
  value: /* -------------------------------------------------------------------------- */
@@ -53,9 +53,13 @@ export declare class SimpleObject extends MapableObject {
53
53
  static getValue<T extends SimpleObject, MKey extends PropOf<T>>(o: T, key: MKey, original?: boolean): PropType<T, MKey> | undefined;
54
54
  /**
55
55
  * set value and run the event handlers if needed
56
- * @return true if changed , false otherwise
56
+ * @param key
57
+ * @param value
58
+ * @param shouldNotify
59
+ * @param autoApply if the field is not in delta, instantly calls the `apply` function to remove from delta
60
+ * @returns
57
61
  */
58
- setValue(key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType): Promise<boolean>;
62
+ setValue(key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType, autoApply?: boolean): Promise<boolean>;
59
63
  /**
60
64
  * set value and run the event handlers if needed
61
65
  *
@@ -63,12 +67,12 @@ export declare class SimpleObject extends MapableObject {
63
67
  * @param key
64
68
  * @param value
65
69
  */
66
- setPreferApply(key: WriteablePropOf<this>, value: any): Promise<boolean>;
70
+ setPreferApply(key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType): Promise<boolean>;
67
71
  /**
68
72
  * set value and run the event handlers if needed
69
73
  * @return true if changed , false otherwise
70
74
  */
71
- set: (key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType) => Promise<boolean>;
75
+ set: (key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType, autoApply?: boolean) => Promise<boolean>;
72
76
  /**
73
77
  * load all properties in `initObject` into the current object
74
78
  * @param initObject
@@ -122,11 +122,17 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
122
122
  value: (
123
123
  /**
124
124
  * set value and run the event handlers if needed
125
- * @return true if changed , false otherwise
125
+ * @param key
126
+ * @param value
127
+ * @param shouldNotify
128
+ * @param autoApply if the field is not in delta, instantly calls the `apply` function to remove from delta
129
+ * @returns
126
130
  */
127
131
  function () {
128
132
  var _setValue = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value) {
129
133
  var shouldNotify,
134
+ autoApply,
135
+ keyExists,
130
136
  old_value,
131
137
  needsChange,
132
138
  _this$manager,
@@ -136,19 +142,21 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
136
142
  while (1) switch (_context.prev = _context.next) {
137
143
  case 0:
138
144
  shouldNotify = _args.length > 2 && _args[2] !== undefined ? _args[2] : "auto";
145
+ autoApply = _args.length > 3 && _args[3] !== undefined ? _args[3] : false;
139
146
  if (this.canModify) {
140
- _context.next = 7;
147
+ _context.next = 8;
141
148
  break;
142
149
  }
143
150
  if (!(this.__throw_errors !== false)) {
144
- _context.next = 6;
151
+ _context.next = 7;
145
152
  break;
146
153
  }
147
154
  throw Error("Cant use setValue (".concat(String(key), ") when on readonly mode"));
148
- case 6:
149
- return _context.abrupt("return", false);
150
155
  case 7:
156
+ return _context.abrupt("return", false);
157
+ case 8:
151
158
  /* --------------------------- set if not changed --------------------------- */
159
+ keyExists = key in this.__delta;
152
160
  old_value = this.getValue(key);
153
161
  needsChange = !(0, _object.object_equals)(old_value, value, {
154
162
  strictArrayCheck: true,
@@ -160,21 +168,29 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
160
168
  * notify the manager when the state of `__has_delta` is changed
161
169
  * managers can use this to detect if they need to save
162
170
  */
163
- (_this$manager = this.manager) === null || _this$manager === void 0 || _this$manager.setOption("ischanged", this.isChanged);
171
+ (_this$manager = this.manager) === null || _this$manager === void 0 || _this$manager.checkIsChanged();
164
172
  ////if (__has_delta_isChanged && this.manager) {
165
173
  //// this.manager.setOption("hasDelta", this.__has_delta);
166
174
  ////}
167
175
  }
176
+ /**
177
+ * if the field is not in delta
178
+ * instantly calls the `apply` function to remove from delta
179
+ */
180
+ if (autoApply && !keyExists) {
181
+ this.apply(key);
182
+ if (shouldNotify === "auto") shouldNotify = false;
183
+ }
168
184
  /* --------------------------------- notify --------------------------------- */
169
185
  if (!(shouldNotify === true || shouldNotify === "auto" && needsChange)) {
170
- _context.next = 13;
186
+ _context.next = 16;
171
187
  break;
172
188
  }
173
- _context.next = 13;
189
+ _context.next = 16;
174
190
  return this.notifyChanged("", key, value);
175
- case 13:
191
+ case 16:
176
192
  return _context.abrupt("return", needsChange);
177
- case 14:
193
+ case 17:
178
194
  case "end":
179
195
  return _context.stop();
180
196
  }
@@ -197,20 +213,17 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
197
213
  key: "setPreferApply",
198
214
  value: (function () {
199
215
  var _setPreferApply = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
200
- var keyExists, res;
216
+ var shouldNotify,
217
+ _args2 = arguments;
201
218
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
202
219
  while (1) switch (_context2.prev = _context2.next) {
203
220
  case 0:
204
- keyExists = key in this.__delta;
221
+ shouldNotify = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : "auto";
205
222
  _context2.next = 3;
206
- return this.set(key, value, keyExists ? "auto" : false);
223
+ return this.set(key, value, shouldNotify, true);
207
224
  case 3:
208
- res = _context2.sent;
209
- if (!keyExists) {
210
- this.apply(key);
211
- }
212
- return _context2.abrupt("return", res);
213
- case 6:
225
+ return _context2.abrupt("return", _context2.sent);
226
+ case 4:
214
227
  case "end":
215
228
  return _context2.stop();
216
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",