dataflux 1.9.3 → 1.9.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.
package/dist/Model.js CHANGED
@@ -416,7 +416,9 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
416
416
  value: function value(objects) {
417
417
  var operation = "insert";
418
418
  return (0, _modelHooksUtils.executeHook)(operation, _classPrivateFieldGet(_this, _insertHook), _classPrivateFieldGet(_this, _unWrap).call(_this, objects), _classPrivateFieldGet(_this, _axios)).then(function (data) {
419
- if (data) _classPrivateFieldGet(_this, _assignId).call(_this, data, objects);
419
+ if (data) {
420
+ _classPrivateFieldGet(_this, _assignId).call(_this, data, objects);
421
+ }
420
422
 
421
423
  _classPrivateFieldGet(_this, _cleanApiError).call(_this, objects);
422
424
 
@@ -432,7 +434,7 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
432
434
  _classPrivateFieldInitSpec(this, _assignId, {
433
435
  writable: true,
434
436
  value: function value(data, objects) {
435
- if (data.length === 1) {
437
+ if (data.length === 1 && objects.length === 1) {
436
438
  var newId = data[0].id;
437
439
  objects[0].setId(newId);
438
440
  delete objects[0].setId;
@@ -81,6 +81,8 @@ var _getUniqueSubs = /*#__PURE__*/new WeakMap();
81
81
 
82
82
  var _propagateChange = /*#__PURE__*/new WeakMap();
83
83
 
84
+ var _appendIfNotExistent = /*#__PURE__*/new WeakMap();
85
+
84
86
  var _subscribeToObjects = /*#__PURE__*/new WeakMap();
85
87
 
86
88
  var _merge = /*#__PURE__*/new WeakMap();
@@ -167,40 +169,41 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
167
169
  });
168
170
 
169
171
  _defineProperty(_assertThisInitialized(_this), "unsubscribe", function (key) {
170
- if (_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).length) {
171
- _classPrivateFieldSet(_assertThisInitialized(_this), _unsubPromises, Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises)).then(function () {
172
- if (_this._multipleSubscribed[key]) {
173
- var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
174
- _step;
172
+ _classPrivateFieldSet(_assertThisInitialized(_this), _unsubPromises, (_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).length ? Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises)) : Promise.resolve()).then(function () {
173
+ if (_this._multipleSubscribed[key]) {
174
+ var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
175
+ _step;
175
176
 
176
- try {
177
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
178
- var sub = _step.value;
177
+ try {
178
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
179
+ var sub = _step.value;
179
180
 
180
- _this.unsubscribe(sub);
181
- }
182
- } catch (err) {
183
- _iterator.e(err);
184
- } finally {
185
- _iterator.f();
181
+ _this.unsubscribe(sub);
186
182
  }
183
+ } catch (err) {
184
+ _iterator.e(err);
185
+ } finally {
186
+ _iterator.f();
187
+ }
187
188
 
188
- delete _this._multipleSubscribed[key];
189
- } else {
190
- for (var type in _this._subscribed) {
191
- for (var id in _this._subscribed[type]) {
192
- _this._subscribed[type][id] = _this._subscribed[type][id].filter(function (i) {
193
- return i.subKey !== key;
194
- });
195
-
196
- if (_this._subscribed[type][id].length === 0) {
197
- delete _this._subscribed[type][id];
198
- }
189
+ delete _this._multipleSubscribed[key];
190
+ } else {
191
+ for (var type in _this._subscribed) {
192
+ for (var id in _this._subscribed[type]) {
193
+ _this._subscribed[type][id] = _this._subscribed[type][id].filter(function (i) {
194
+ return i.subKey !== key;
195
+ });
196
+ _this._subscribed[type]["*"] = _this._subscribed[type]["*"].filter(function (i) {
197
+ return i.subKey !== key;
198
+ });
199
+
200
+ if (_this._subscribed[type][id].length === 0) {
201
+ delete _this._subscribed[type][id];
199
202
  }
200
203
  }
201
204
  }
202
- }));
203
- }
205
+ }
206
+ }));
204
207
  });
205
208
 
206
209
  _classPrivateFieldInitSpec(_assertThisInitialized(_this), _getUniqueSubs, {
@@ -266,27 +269,45 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
266
269
  }
267
270
  });
268
271
 
272
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _appendIfNotExistent, {
273
+ writable: true,
274
+ value: function value(arr, item) {
275
+ if (Object.values(arr).filter(function (_ref4) {
276
+ var subKey = _ref4.subKey;
277
+ return item.subKey === subKey;
278
+ }).length === 0) {
279
+ arr.push(item);
280
+ }
281
+ }
282
+ });
283
+
269
284
  _classPrivateFieldInitSpec(_assertThisInitialized(_this), _subscribeToObjects, {
270
285
  writable: true,
271
286
  value: function value(type, objectsToSubscribe, item) {
287
+ var _this$_subscribed$typ2, _, _this$_subscribed$typ3;
288
+
272
289
  var _iterator4 = _createForOfIteratorHelper(objectsToSubscribe),
273
290
  _step4;
274
291
 
275
292
  try {
276
293
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
277
- var _this$_subscribed$typ2, _this$_subscribed$typ3;
294
+ var _this$_subscribed$typ4, _this$_subscribed$typ5;
278
295
 
279
296
  var object = _step4.value;
280
297
  var id = object.getId();
281
- (_this$_subscribed$typ3 = (_this$_subscribed$typ2 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ3 !== void 0 ? _this$_subscribed$typ3 : _this$_subscribed$typ2[id] = [];
298
+ (_this$_subscribed$typ5 = (_this$_subscribed$typ4 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ5 !== void 0 ? _this$_subscribed$typ5 : _this$_subscribed$typ4[id] = [];
282
299
 
283
- _this._subscribed[type][id].push(item);
300
+ _classPrivateFieldGet(_assertThisInitialized(_this), _appendIfNotExistent).call(_assertThisInitialized(_this), _this._subscribed[type][id], item);
284
301
  }
285
302
  } catch (err) {
286
303
  _iterator4.e(err);
287
304
  } finally {
288
305
  _iterator4.f();
289
306
  }
307
+
308
+ (_this$_subscribed$typ3 = (_this$_subscribed$typ2 = _this._subscribed[type])[_ = "*"]) !== null && _this$_subscribed$typ3 !== void 0 ? _this$_subscribed$typ3 : _this$_subscribed$typ2[_] = [];
309
+
310
+ _classPrivateFieldGet(_assertThisInitialized(_this), _appendIfNotExistent).call(_assertThisInitialized(_this), _this._subscribed[type]["*"], item);
290
311
  }
291
312
  });
292
313
 
@@ -297,11 +318,11 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
297
318
  model: type
298
319
  });
299
320
 
300
- return _this.refreshObjectByType(type).then(function (_ref4) {
301
- var _ref5 = _slicedToArray(_ref4, 3),
302
- inserted = _ref5[0],
303
- updated = _ref5[1],
304
- deleted = _ref5[2];
321
+ return _this.refreshObjectByType(type).then(function (_ref5) {
322
+ var _ref6 = _slicedToArray(_ref5, 3),
323
+ inserted = _ref6[0],
324
+ updated = _ref6[1],
325
+ deleted = _ref6[2];
305
326
 
306
327
  var item = _this.models[type];
307
328
  return Promise.all([_classPrivateMethodGet(_assertThisInitialized(_this), _propagateInsertChange, _propagateInsertChange2).call(_assertThisInitialized(_this), type, inserted), _classPrivateFieldGet(_assertThisInitialized(_this), _propagateChange).call(_assertThisInitialized(_this), updated), _classPrivateFieldGet(_assertThisInitialized(_this), _propagateChange).call(_assertThisInitialized(_this), deleted)]).then(function () {
@@ -412,34 +433,15 @@ function _propagateInsertChange2(type, newObjects) {
412
433
  }
413
434
 
414
435
  var possibleSubs = Object.values(uniqueSubs);
415
- (0, _batchPromises["default"])(10, possibleSubs, function (_ref6) {
416
- var callback = _ref6.callback,
417
- filterFunction = _ref6.filterFunction;
436
+ (0, _batchPromises["default"])(10, possibleSubs, function (_ref7) {
437
+ var callback = _ref7.callback,
438
+ filterFunction = _ref7.filterFunction,
439
+ subKey = _ref7.subKey;
418
440
  var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
419
441
 
420
442
  if (objectsToSubscribe.length) {
421
443
  // Check if the new objects matter
422
444
  return _this4.find(type, filterFunction).then(function (data) {
423
- var subKey;
424
-
425
- var _iterator6 = _createForOfIteratorHelper(data),
426
- _step6;
427
-
428
- try {
429
- for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
430
- var d = _step6.value;
431
-
432
- var item = _this4._subscribed[d.getModel().getType()][d.getId()];
433
-
434
- subKey = item ? item.subKey : null;
435
- if (subKey) break;
436
- }
437
- } catch (err) {
438
- _iterator6.e(err);
439
- } finally {
440
- _iterator6.f();
441
- }
442
-
443
445
  _classPrivateFieldGet(_this4, _subscribeToObjects).call(_this4, type, objectsToSubscribe, {
444
446
  callback: callback,
445
447
  filterFunction: filterFunction,