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