dataflux 1.4.1 → 1.4.2

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.
Files changed (3) hide show
  1. package/README.md +16 -12
  2. package/dist/Obj.js +6 -0
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -160,6 +160,8 @@ If now a book is inserted/deleted/edited:
160
160
  * if the book has `price < 20`, `drawBooksCallback` will be called again with the new dataset;
161
161
  * if the book has `price > 20`, `drawBooksCallback` will NOT be called again (because the new book doesn't impact our selection).
162
162
 
163
+ > Warning: if you edit the objects inside your callback (e.g., you do `.set()`), you will trigger the subscription's callback again in an infinite loop! If you want to set an attribute of an object inside your callback, before drawing it, use `setConstant()`.
164
+
163
165
  You can terminate the subscription with `store.unsubscribe()`:
164
166
 
165
167
  ```js
@@ -481,18 +483,20 @@ The store emits the following events:
481
483
  Each object created is enriched with the following methods.
482
484
 
483
485
 
484
- | Method | Description |
485
- |------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
486
- | 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. |
487
- | 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). |
488
- | save() | Method to save the object. You can do `store.save()` instead. |
489
- | destroy() | Method to delete the object. You can do `store.delete()` instead. |
490
- | 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, 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. |
491
- | getRelation(model, filterFunction) | To get all the objects respecting a specific relation with this object (see [model relations](#model-relations)). |
492
- | toJSON() | It returns a pure JSON representation of the object. |
493
- | toString() | It returns a string representation of the object. |
494
- | getFingerprint() | It returns a hash of the object. The hash changes at every change of the object or of any nested object. Useful to detect object changes. |
495
- | getModel() | It returns the model of this object. Mostly useful to do `object.getModel().getType()` and obtain a string defining the type of the object. |
486
+ | Method | Description |
487
+ |------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
488
+ | 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. |
489
+ | 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)). |
490
+ | 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. |
491
+ | 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. |
492
+ | getRelation(model, filterFunction) | To get all the objects respecting a specific relation with this object (see [model relations](#model-relations)). |
493
+ | save() | Method to save the object. You can do `store.save()` instead. |
494
+ | destroy() | Method to delete the object. You can do `store.delete()` instead. |
495
+
496
+ | toJSON() | It returns a pure JSON representation of the object. |
497
+ | toString() | It returns a string representation of the object. |
498
+ | getFingerprint() | It returns a hash of the object. The hash changes at every change of the object or of any nested object. Useful to detect object changes. |
499
+ | getModel() | It returns the model of this object. Mostly useful to do `object.getModel().getType()` and obtain a string defining the type of the object. |
496
500
 
497
501
  ## Editing objects
498
502
  The option `autoSave` can be `true`, `false`, or a number (milliseconds).
package/dist/Obj.js CHANGED
@@ -100,6 +100,12 @@ var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
100
100
  return _this.getModel().getStore().update([_this]);
101
101
  });
102
102
 
103
+ _defineProperty(this, "setConstant", function (attribute, value) {
104
+ var _classPrivateFieldGet3;
105
+
106
+ _classPrivateFieldGet(_this, _setHidden)[attribute] = (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet3 !== void 0 ? _classPrivateFieldGet3 : value;
107
+ });
108
+
103
109
  _defineProperty(this, "save", function () {
104
110
  return _this.getModel().getStore().save([_this]);
105
111
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataflux",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "DataFlux, automatically interfaces with your REST APIs to create a 2-way-synced local data store. Transparently manages data propagation in the React state.",
5
5
  "main": "dist/index.js",
6
6
  "bin": "dist/index.js",