dataflux 1.24.2 → 1.24.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/README.md CHANGED
@@ -713,7 +713,7 @@ Each object created is enriched with the following methods.
713
713
  | isDataflux() | This method returns true for all dataflux objects. |
714
714
  | isMock() | This method returns true if the object is a mock and was never inserted in the store. |
715
715
  | isPersisted() | This method returns true if the object has been persisted to the server at least once. This does not mean that the server’s copy is up to date with the client’s copy. |
716
-
716
+ | hasChanged() | This method returns true if the object has changed since the last sync with the server. |
717
717
  ### Deep Objects
718
718
  When a model is declared with the option `deep: true` (default, see [model creation](#models-creation)), all the sub objects will also offer many of the methods above.
719
719
 
package/dist/BasicObj.js CHANGED
@@ -173,6 +173,9 @@ var BasicObj = exports.BasicObj = /*#__PURE__*/function () {
173
173
  _defineProperty(this, "update", function () {
174
174
  return Promise.resolve();
175
175
  });
176
+ _defineProperty(this, "hasChanged", function () {
177
+ return _classPrivateFieldGet(_model, _this).getStore().hasChanged(_classPrivateFieldGet(_model, _this).getType(), _this);
178
+ });
176
179
  _classPrivateFieldSet(_model, this, model);
177
180
  }
178
181
  return _createClass(BasicObj, [{
package/dist/Model.js CHANGED
@@ -160,23 +160,25 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
160
160
  });
161
161
  _defineProperty(this, "load", function (obj, callback) {
162
162
  if (_classPrivateFieldGet(_loadFunction, _this)) {
163
- return _this.getStore().whenSaved(_this.getType())["catch"](function (e) {
164
- throw new Error("You cannot perform load() on an unsaved object.");
165
- }).then(function () {
166
- var res = _classPrivateFieldGet(_loadFunction, _this).call(_this, obj.toJSON()); // toJSON to avoid side effects;
167
-
168
- if (typeof res === "string") {
169
- return _classPrivateFieldGet(_axios, _this).call(_this, {
170
- method: "get",
171
- url: res,
172
- responseType: "json"
173
- }).then(function (data) {
174
- return data.data;
175
- }).then(function (data) {
176
- return callback ? callback(data) : data;
177
- });
163
+ return Promise.resolve().then(function () {
164
+ if (!obj.isPersisted() || obj.hasChanged()) {
165
+ return Promise.reject("You cannot perform load() on an unsaved object.");
178
166
  } else {
179
- return res;
167
+ var res = _classPrivateFieldGet(_loadFunction, _this).call(_this, obj.toJSON()); // toJSON to avoid side effects;
168
+
169
+ if (typeof res === "string") {
170
+ return _classPrivateFieldGet(_axios, _this).call(_this, {
171
+ method: "get",
172
+ url: res,
173
+ responseType: "json"
174
+ }).then(function (data) {
175
+ return data.data;
176
+ }).then(function (data) {
177
+ return callback ? callback(data) : data;
178
+ });
179
+ } else {
180
+ return res;
181
+ }
180
182
  }
181
183
  }).then(function (data) {
182
184
  (0, _BasicObj.setValues)(data, _this, _SubObj["default"], obj, obj);
@@ -35,7 +35,6 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
35
35
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
36
36
  function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
37
37
  function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
38
- function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
39
38
  function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
40
39
  function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } /*
41
40
  * MIT License
@@ -119,7 +118,7 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
119
118
  return subKey;
120
119
  });
121
120
  _defineProperty(_this, "unsubscribe", function (key) {
122
- _classPrivateFieldSet(_unsubPromises, _this, (_classPrivateFieldGet(_queryPromises, _this).length ? Promise.all(_classPrivateFieldGet(_queryPromises, _this)) : Promise.resolve()).then(function () {
121
+ var prom = (_classPrivateFieldGet(_queryPromises, _this).length ? Promise.all(_classPrivateFieldGet(_queryPromises, _this)) : Promise.resolve()).then(function () {
123
122
  if (_this._multipleSubscribed[key]) {
124
123
  var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
125
124
  _step;
@@ -151,7 +150,11 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
151
150
  }
152
151
  }
153
152
  }
154
- }));
153
+ })["finally"](function () {
154
+ var idx = _classPrivateFieldGet(_unsubPromises, _this).indexOf(prom);
155
+ if (idx !== -1) _classPrivateFieldGet(_unsubPromises, _this).splice(idx, 1);
156
+ });
157
+ _classPrivateFieldGet(_unsubPromises, _this).push(prom);
155
158
  });
156
159
  _classPrivateFieldInitSpec(_this, _getUniqueSubs, function (objects, type) {
157
160
  var out = {};