dataflux 1.12.3 → 1.13.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
@@ -569,7 +569,8 @@ The store has the following method.
569
569
  | preload(type) | This method allows to preLoad all objects of a given model. If you initialize the store with `lazyLoad:true`, the objects of a model are retrieved from the API at the first query performed on that model (e.g., at the first `.find()`). However, sometimes you may want to speed up the first query by pre loading the objects of a specific model while keeping `lazyLoad:true` on the store; in such a case you can use `store.preload(type)`. |
570
570
  | save() | Persist the changes. Edited local objects will be sent to the REST APIs (insert/update/delete). See also [editing objects](#editing-objects). |
571
571
  | 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). |
572
- | 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). |
572
+ | refresh(type) | 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). If a model type is passed, only objects of that type will be refreshed. |
573
+ | reset(type) | 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 reverted to the corresponding remote object. If a model type is passed, only objects of that type will be reset. |
573
574
  | 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.* |
574
575
 
575
576
  ### Insert vs. Mock
@@ -250,13 +250,19 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
250
250
  _classPrivateFieldGet(_assertThisInitialized(_this), _appendIfNotExistent).call(_assertThisInitialized(_this), _this._subscribed[type]["*"], item);
251
251
  }
252
252
  });
253
+ _defineProperty(_assertThisInitialized(_this), "reset", function (type) {
254
+ return _this._refresh(type, true);
255
+ });
253
256
  _defineProperty(_assertThisInitialized(_this), "refresh", function (type) {
257
+ return _this._refresh(type, false);
258
+ });
259
+ _defineProperty(_assertThisInitialized(_this), "_refresh", function (type, force) {
254
260
  var refreshByType = function refreshByType(type) {
255
261
  _this.pubSub.publish("refresh", {
256
262
  status: "start",
257
263
  model: type
258
264
  });
259
- return _this.refreshObjectByType(type).then(function (_ref5) {
265
+ return _this.refreshObjectByType(type, force).then(function (_ref5) {
260
266
  var _ref6 = _slicedToArray(_ref5, 3),
261
267
  inserted = _ref6[0],
262
268
  updated = _ref6[1],
package/dist/Store.js CHANGED
@@ -49,6 +49,7 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
49
49
  */
50
50
  var objectStatuses = ["new", "old", "mock", "deleted"];
51
51
  var _merge = /*#__PURE__*/new WeakMap();
52
+ var _wipe = /*#__PURE__*/new WeakMap();
52
53
  var _error = /*#__PURE__*/new WeakSet();
53
54
  var _deleteByObject = /*#__PURE__*/new WeakMap();
54
55
  var _deleteByFilter = /*#__PURE__*/new WeakSet();
@@ -77,6 +78,7 @@ var Store = /*#__PURE__*/function () {
77
78
  return filterFunction ? all.filter(filterFunction) : all;
78
79
  });
79
80
  _defineProperty(this, "refreshObjectByType", function (type) {
81
+ var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
80
82
  return _this._getPromise(type).then(function () {
81
83
  var item = _this.models[type];
82
84
  var inserted = [];
@@ -107,7 +109,12 @@ var Store = /*#__PURE__*/function () {
107
109
  var oldFingerprint = currentObject.fingerprint;
108
110
  if (oldFingerprint !== newFingerprint) {
109
111
  // Nothing to do otherwise
110
- if (_this.hasChanged(type, currentObject.object)) {// Was the object edited locally?
112
+ if (force) {
113
+ _classPrivateFieldGet(_this, _wipe).call(_this, currentObject.object);
114
+ _classPrivateFieldGet(_this, _merge).call(_this, currentObject.object, wrapper.toJSON());
115
+ currentObject.fingerprint = newFingerprint;
116
+ updated.push(currentObject.object);
117
+ } else if (_this.hasChanged(type, currentObject.object)) {// Was the object edited locally?
111
118
 
112
119
  // Nothing for now
113
120
  } else {
@@ -148,7 +155,16 @@ var Store = /*#__PURE__*/function () {
148
155
  for (var key in newObject) {
149
156
  originalObject[key] = newObject[key];
150
157
  }
151
- // originalObject.update();
158
+ }
159
+ });
160
+ _classPrivateFieldInitSpec(this, _wipe, {
161
+ writable: true,
162
+ value: function value(originalObject) {
163
+ for (var key in originalObject) {
164
+ if (key !== "id") {
165
+ delete originalObject[key];
166
+ }
167
+ }
152
168
  }
153
169
  });
154
170
  _classPrivateFieldInitSpec(this, _deleteByObject, {