dataflux 1.24.1 → 1.24.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.
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);
package/dist/Obj.js CHANGED
@@ -72,7 +72,7 @@ var Obj = exports["default"] = /*#__PURE__*/function (_BasicObj) {
72
72
  return i !== null && i !== void 0 && i.getId ? i : new _SubObj["default"](_this, "property", i, _this.getModel());
73
73
  }
74
74
  });
75
- } else if (_typeof(value) === "object") {
75
+ } else if (_typeof(value) === "object" && value !== null) {
76
76
  var _value;
77
77
  value = (_value = value) !== null && _value !== void 0 && _value.getId ? value : new _SubObj["default"](_this, "property", value, _this.getModel());
78
78
  }