dataflux 1.10.5 → 1.11.0

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/README.md CHANGED
@@ -568,6 +568,8 @@ The store has the following method.
568
568
  | save() | Persist the changes. Edited local objects will be sent to the REST APIs (insert/update/delete). See also [editing objects](#editing-objects). |
569
569
  | save() | Persist the changes (`local -> remote`). Edited local objects will be sent to the REST APIs (insert/update/delete). See also [editing objects](#editing-objects). |
570
570
  | refresh() | This method syncs all the objects in the store with the remote version offered by the REST APIs (`remote -> local`). Remote changes are applied locally, including adding/removing objects. Objects edited locally but not yet persisted are preserved locally (tip: you can also create a store with the `autoRefresh` option). |
571
+ | findSync(type, filterFunction) | This method returns the objects in a synchronous way (no Promise). However, *it works only if you already performed an async operation (e.g., like refresh, load, find, subscribe) or if you set lazyLoad to false and the store had enough time to load.* |
572
+
571
573
  ### Insert vs. Mock
572
574
 
573
575
  If you do:
package/dist/Model.js CHANGED
@@ -118,7 +118,7 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
118
118
  if (validate && validate[key]) {
119
119
  try {
120
120
  var call = validate[key](object, _classPrivateFieldGet(_this, _store));
121
- if (call.then) {
121
+ if (call !== null && call !== void 0 && call.then) {
122
122
  call.then(function () {
123
123
  return object.setError(false, key);
124
124
  })["catch"](function (error) {
package/dist/Store.js CHANGED
@@ -27,7 +27,6 @@ var _merge = /*#__PURE__*/new WeakMap();
27
27
  var _error = /*#__PURE__*/new WeakSet();
28
28
  var _deleteByObject = /*#__PURE__*/new WeakMap();
29
29
  var _deleteByFilter = /*#__PURE__*/new WeakSet();
30
- var _getPromise = /*#__PURE__*/new WeakSet();
31
30
  var _insertObject = /*#__PURE__*/new WeakMap();
32
31
  var _loadObjects = /*#__PURE__*/new WeakSet();
33
32
  var Store = /*#__PURE__*/function () {
@@ -38,14 +37,21 @@ var Store = /*#__PURE__*/function () {
38
37
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
39
38
  _classCallCheck(this, Store);
40
39
  _classPrivateMethodInitSpec(this, _loadObjects);
41
- _classPrivateMethodInitSpec(this, _getPromise);
42
40
  _classPrivateMethodInitSpec(this, _deleteByFilter);
43
41
  _classPrivateMethodInitSpec(this, _error);
44
42
  _defineProperty(this, "getModels", function () {
45
43
  return Object.keys(_this.models);
46
44
  });
45
+ _defineProperty(this, "findSync", function (type, filterFunction) {
46
+ var all = Object.values(_this.models[type].storedObjects).filter(function (i) {
47
+ return i.status !== "deleted";
48
+ }).map(function (i) {
49
+ return i.object;
50
+ });
51
+ return filterFunction ? all.filter(filterFunction) : all;
52
+ });
47
53
  _defineProperty(this, "refreshObjectByType", function (type) {
48
- return _classPrivateMethodGet(_this, _getPromise, _getPromise2).call(_this, type).then(function () {
54
+ return _this._getPromise(type).then(function () {
49
55
  var item = _this.models[type];
50
56
  var inserted = [];
51
57
  var deleted = [];
@@ -232,7 +238,7 @@ var Store = /*#__PURE__*/function () {
232
238
  key: "insert",
233
239
  value: function insert(type, objects) {
234
240
  var _this3 = this;
235
- return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
241
+ return this._getPromise(type).then(function () {
236
242
  return objects.map(function (object) {
237
243
  return _classPrivateFieldGet(_this3, _insertObject).call(_this3, type, object, "new");
238
244
  });
@@ -242,7 +248,7 @@ var Store = /*#__PURE__*/function () {
242
248
  key: "mock",
243
249
  value: function mock(type, objects) {
244
250
  var _this4 = this;
245
- return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
251
+ return this._getPromise(type).then(function () {
246
252
  return objects.map(function (object) {
247
253
  return _classPrivateFieldGet(_this4, _insertObject).call(_this4, type, object, "mock");
248
254
  });
@@ -252,7 +258,7 @@ var Store = /*#__PURE__*/function () {
252
258
  key: "get",
253
259
  value: function get(type, id) {
254
260
  var _this5 = this;
255
- return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
261
+ return this._getPromise(type).then(function () {
256
262
  try {
257
263
  return _this5.models[type].storedObjects[id].object;
258
264
  } catch (error) {
@@ -264,13 +270,8 @@ var Store = /*#__PURE__*/function () {
264
270
  key: "find",
265
271
  value: function find(type, filterFunction) {
266
272
  var _this6 = this;
267
- return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
268
- var all = Object.values(_this6.models[type].storedObjects).filter(function (i) {
269
- return i.status !== "deleted";
270
- }).map(function (i) {
271
- return i.object;
272
- });
273
- return filterFunction ? all.filter(filterFunction) : all;
273
+ return this._getPromise(type).then(function () {
274
+ return _this6.findSync(type, filterFunction);
274
275
  })["catch"](function (error) {
275
276
  _this6.pubSub.publish("error", error);
276
277
  return Promise.reject(error);
@@ -336,13 +337,13 @@ var Store = /*#__PURE__*/function () {
336
337
  }, {
337
338
  key: "preload",
338
339
  value: function preload(type) {
339
- return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type);
340
+ return this._getPromise(type);
340
341
  }
341
342
  }, {
342
343
  key: "getDiff",
343
344
  value: function getDiff(type) {
344
345
  var _this8 = this;
345
- return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
346
+ return this._getPromise(type).then(function () {
346
347
  var objects = Object.values(_this8.models[type].storedObjects);
347
348
  var inserted = [];
348
349
  var updated = [];
@@ -394,6 +395,22 @@ var Store = /*#__PURE__*/function () {
394
395
  });
395
396
  return item.promise;
396
397
  }
398
+ }, {
399
+ key: "_getPromise",
400
+ value: function _getPromise(type) {
401
+ var _this10 = this;
402
+ if (!this.models[type]) {
403
+ return Promise.reject("The model doesn't exist");
404
+ } else if (!this.models[type].promise && !this.options.lazyLoad) {
405
+ return Promise.reject("The model is not loaded");
406
+ } else if (!this.models[type].promise && this.options.lazyLoad) {
407
+ return _classPrivateMethodGet(this, _loadObjects, _loadObjects2).call(this, type).then(function () {
408
+ return _this10.models[type].promise;
409
+ });
410
+ } else {
411
+ return this.models[type].promise;
412
+ }
413
+ }
397
414
  }]);
398
415
  return Store;
399
416
  }();
@@ -404,9 +421,9 @@ function _error2(error) {
404
421
  return Promise.reject(error);
405
422
  }
406
423
  function _deleteByFilter2(type, filterFunction) {
407
- var _this10 = this;
408
- return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
409
- var deleted = Object.values(_this10.models[type].storedObjects).filter(function (i) {
424
+ var _this11 = this;
425
+ return this._getPromise(type).then(function () {
426
+ var deleted = Object.values(_this11.models[type].storedObjects).filter(function (i) {
410
427
  return filterFunction(i.object);
411
428
  });
412
429
  var _iterator5 = _createForOfIteratorHelper(deleted),
@@ -426,20 +443,6 @@ function _deleteByFilter2(type, filterFunction) {
426
443
  });
427
444
  });
428
445
  }
429
- function _getPromise2(type) {
430
- var _this11 = this;
431
- if (!this.models[type]) {
432
- return Promise.reject("The model doesn't exist");
433
- } else if (!this.models[type].promise && !this.options.lazyLoad) {
434
- return Promise.reject("The model is not loaded");
435
- } else if (!this.models[type].promise && this.options.lazyLoad) {
436
- return _classPrivateMethodGet(this, _loadObjects, _loadObjects2).call(this, type).then(function () {
437
- return _this11.models[type].promise;
438
- });
439
- } else {
440
- return this.models[type].promise;
441
- }
442
- }
443
446
  function _loadObjects2(type) {
444
447
  var _this12 = this;
445
448
  var item = this.models[type];