dataflux 1.21.2 → 1.22.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
@@ -696,6 +696,7 @@ Each object created is enriched with the following methods.
696
696
  |------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
697
697
  | getId() | It returns a unique ID used by the store to identify the object. The ID is unique inside a single model. Be aware, `object.id` and `objet.getId()` may return different values, since store's IDs can be different from the one of the REST API. |
698
698
  | set(attribute, value, hidden) | A method to set an attribute to the object. It provides some advantages compared to doing `object.attribute = value`, these are discussed in [below](#editing-objects). The third parameter is optional, and when set to true will set the attribute as hidden (see [hiddenFields](#models-creation)). |
699
+ | delete(attribute) | A method to delete an attribute of the object. |
699
700
  | setConstant(attribute, value) | A method to set an unmodifiable hidden attribute on the object. Setting the attribute as a constant will not propagate an update. |
700
701
  | get(attribute, defaultValue) | Method to retrieve the value of an attribute. It does not provide any advantage compared to accessing directly the attribute (e.g., `author.name`); except for hidden fields and constants, which can be retrieved only with the `.get` method. Additionally, you can provide a default value as a second parameter in case the object doesn't have that attribute. |
701
702
  | getRelation(model, filterFunction) | To get all the objects respecting a specific relation with this object (see [model relations](#model-relations)). |
@@ -709,6 +710,8 @@ Each object created is enriched with the following methods.
709
710
  | getError(attributeName) | This method allows you to check if the specificed attribute generated any error according to the validation property specified in the model. See [objects validation](#objects-validation). |
710
711
  | setError(error) | Additionally to DataFlux's errors, you can trigger your own errors with this method. Other components observing this objet's error will be notified. |
711
712
  | isDataflux() | This method returns true for all dataflux objects. |
713
+ | isMock() | This method returns true if the object is a mock and was never inserted in the store. |
714
+ | 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. |
712
715
 
713
716
  ### Deep Objects
714
717
  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.
package/dist/BasicObj.js CHANGED
@@ -96,6 +96,9 @@ var BasicObj = exports.BasicObj = /*#__PURE__*/function () {
96
96
  _defineProperty(this, "isDataflux", function () {
97
97
  return true;
98
98
  });
99
+ _defineProperty(this, "isPersisted", function () {
100
+ return true;
101
+ });
99
102
  _defineProperty(this, "isMock", function () {
100
103
  return false;
101
104
  });
@@ -173,6 +176,13 @@ var BasicObj = exports.BasicObj = /*#__PURE__*/function () {
173
176
  _classPrivateFieldSet(_model, this, model);
174
177
  }
175
178
  return _createClass(BasicObj, [{
179
+ key: "delete",
180
+ value: function _delete(attribute) {
181
+ delete _classPrivateFieldGet(_setHidden, this)[attribute];
182
+ delete this[attribute];
183
+ return this.update();
184
+ }
185
+ }, {
176
186
  key: "set",
177
187
  value: function set(attribute, value, hidden) {
178
188
  if (hidden) {
package/dist/Obj.js CHANGED
@@ -59,6 +59,9 @@ var Obj = exports["default"] = /*#__PURE__*/function (_BasicObj) {
59
59
  _classCallCheck(this, Obj);
60
60
  _this = _callSuper(this, Obj, [values, _model]);
61
61
  _classPrivateFieldInitSpec(_this, _loaded, false);
62
+ _defineProperty(_this, "delete", function (attribute) {
63
+ return _superPropGet((_this, Obj), "delete", _this, 3)([attribute]);
64
+ });
62
65
  _defineProperty(_this, "set", function (attribute, value, hidden) {
63
66
  if (Array.isArray(value) && _this.getModel().options.deep) {
64
67
  value = value.map(function (i) {
package/dist/Store.js CHANGED
@@ -214,6 +214,11 @@ var Store = exports["default"] = /*#__PURE__*/function () {
214
214
  var model = _this.models[type].model;
215
215
  var wrapper = new _Obj["default"](item, model);
216
216
  var id = wrapper.getId();
217
+ if (status === "new" || status === "mock") {
218
+ wrapper.isPersisted = function () {
219
+ return false;
220
+ };
221
+ }
217
222
  if (_this.models[type].storedObjects[id]) {
218
223
  throw new Error("The IDs provided for the model ".concat(type, " are not unique"));
219
224
  }
@@ -384,6 +389,9 @@ var Store = exports["default"] = /*#__PURE__*/function () {
384
389
  }
385
390
  item.fingerprint = object.object.getFingerprint();
386
391
  item.status = "old";
392
+ item.object.isPersisted = function () {
393
+ return true;
394
+ };
387
395
  }
388
396
  } catch (err) {
389
397
  _iterator3.e(err);
package/dist/SubObj.js CHANGED
@@ -66,6 +66,9 @@ var SubObj = exports["default"] = /*#__PURE__*/function (_BasicObj) {
66
66
  _defineProperty(_this, "set", function (attribute, value, hidden) {
67
67
  return _superPropGet((_this, SubObj), "set", _this, 3)([attribute, value, hidden]);
68
68
  });
69
+ _defineProperty(_this, "delete", function (attribute) {
70
+ return _superPropGet((_this, SubObj), "delete", _this, 3)([attribute]);
71
+ });
69
72
  _defineProperty(_this, "save", function () {
70
73
  return _classPrivateFieldGet(_model, _this).getStore().save([_classPrivateFieldGet(_parent, _this)]);
71
74
  });