@azrico/webobject 1.5.2 → 1.5.3

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.
@@ -53,22 +53,27 @@ 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
  *
62
66
  * if the field is not in delta instantly calls the `apply` function to remove from delta
63
67
  * @param key
64
68
  * @param value
69
+ * @returns true if `apply` function is used
65
70
  */
66
- setPreferApply(key: WriteablePropOf<this>, value: any): Promise<boolean>;
71
+ setPreferApply(key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType): Promise<boolean>;
67
72
  /**
68
73
  * set value and run the event handlers if needed
69
74
  * @return true if changed , false otherwise
70
75
  */
71
- set: (key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType) => Promise<boolean>;
76
+ set: (key: WriteablePropOf<this>, value: any, shouldNotify?: sendChangesType, autoApply?: boolean) => Promise<boolean>;
72
77
  /**
73
78
  * load all properties in `initObject` into the current object
74
79
  * @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,
@@ -165,16 +173,24 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
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
  }
@@ -191,26 +207,24 @@ var SimpleObject = exports.SimpleObject = /*#__PURE__*/function (_MapableObject)
191
207
  * if the field is not in delta instantly calls the `apply` function to remove from delta
192
208
  * @param key
193
209
  * @param value
210
+ * @returns true if `apply` function is used
194
211
  */
195
212
  )
196
213
  }, {
197
214
  key: "setPreferApply",
198
215
  value: (function () {
199
216
  var _setPreferApply = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, value) {
200
- var keyExists, res;
217
+ var shouldNotify,
218
+ _args2 = arguments;
201
219
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
202
220
  while (1) switch (_context2.prev = _context2.next) {
203
221
  case 0:
204
- keyExists = key in this.__delta;
222
+ shouldNotify = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : "auto";
205
223
  _context2.next = 3;
206
- return this.set(key, value, keyExists ? "auto" : false);
224
+ return this.set(key, value, shouldNotify, true);
207
225
  case 3:
208
- res = _context2.sent;
209
- if (!keyExists) {
210
- this.apply(key);
211
- }
212
- return _context2.abrupt("return", res);
213
- case 6:
226
+ return _context2.abrupt("return", _context2.sent);
227
+ case 4:
214
228
  case "end":
215
229
  return _context2.stop();
216
230
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azrico/webobject",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Stateful object",
5
5
  "author": "Azrideus",
6
6
  "license": "MIT",