dataflux 1.3.0 → 1.4.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 +31 -26
- package/dist/Model.js +40 -6
- package/dist/Obj.js +26 -6
- package/dist/ObserverStore.js +35 -20
- 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
|
|
@@ -176,7 +178,8 @@ const subscriptions = [
|
|
|
176
178
|
["author"], // No filter function, all objects returned
|
|
177
179
|
];
|
|
178
180
|
|
|
179
|
-
const callback = (
|
|
181
|
+
const callback = (data) => {
|
|
182
|
+
const {book, author} = data;
|
|
180
183
|
// Objects are ready
|
|
181
184
|
};
|
|
182
185
|
|
|
@@ -261,18 +264,18 @@ const book = new Model("book", options);
|
|
|
261
264
|
|
|
262
265
|
All the possible options for a model creation are (they are all optional):
|
|
263
266
|
|
|
264
|
-
| Name
|
|
265
|
-
|
|
266
|
-
| retrieve
|
|
267
|
-
| insert
|
|
268
|
-
| update
|
|
269
|
-
| delete
|
|
270
|
-
| fields
|
|
271
|
-
| headers
|
|
272
|
-
| load
|
|
273
|
-
| axios
|
|
274
|
-
| parseMoment
|
|
275
|
-
|
|
267
|
+
| Name | Description | Default |
|
|
268
|
+
|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
|
|
269
|
+
| retrieve | Describes the operation to retrieve the collection of objects from the REST API. It can be an operation object or a function. See [operations](#operations). | `{method: "get"}` |
|
|
270
|
+
| insert | Describes the operation to insert a new object in the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "post"}` |
|
|
271
|
+
| update | Describes the operation to update objects of the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "put"}` |
|
|
272
|
+
| delete | Describes the operation to remove objects from the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "delete"}` |
|
|
273
|
+
| fields | An array of strings defining which attributes the retrieved objects should have. Essentially, it allows you to contemporarily specify the [X-Fields header](https://flask-restplus.readthedocs.io/en/stable/mask.html) and the [fields GET parameter](https://developers.google.com/slides/api/guides/performance#partial). This reduces transfer size and memory usage. E.g., if you have a collection of books, of which you are interested only in the name, you can define `fields: ["name"]`. In combination with `load` it allows for partial lazy load of the objects. | All the fields |
|
|
274
|
+
| headers | A dictionary of headers for the HTTP request. E.g., `{"Authorization": "bearer XXXX"}`. | No headers |
|
|
275
|
+
| load | A function that allows to enrich the objects on demand. E.g., you can use `fields` to download only the titles of a collection of books, and `load` to load completely the object. See [object enrichment](#object-enrichment). |
|
|
276
|
+
| axios | It allows to specify an axios instance to be used for the queries. If not specified, a new one will be used. | A new axios instance |
|
|
277
|
+
| parseMoment | Automatically creates Moment.js objects out of ISO8601 strings. E.g., if an object has a property `createdAt: "2022-01-07T21:38:50.295Z"`, this will be transformed to a moment object. | |
|
|
278
|
+
| hiddenFields | An array of attribute names that will never be sent back to the API. E.g., if you set `hiddenFields: ["pages"]`, a book object can contain an attribute `pages` locally, but this will be stripped out in PUT/POST requests. |
|
|
276
279
|
|
|
277
280
|
### Operations
|
|
278
281
|
As described in the table above, there are four possible operations: **retrieve, insert, update,** and **delete**. An operation can be defined as an operation object or a function.
|
|
@@ -481,18 +484,20 @@ The store emits the following events:
|
|
|
481
484
|
Each object created is enriched with the following methods.
|
|
482
485
|
|
|
483
486
|
|
|
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)
|
|
488
|
-
|
|
|
489
|
-
|
|
|
490
|
-
|
|
|
491
|
-
|
|
|
492
|
-
|
|
|
493
|
-
|
|
494
|
-
|
|
|
495
|
-
|
|
|
487
|
+
| Method | Description |
|
|
488
|
+
|------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
489
|
+
| 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. |
|
|
490
|
+
| 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)). |
|
|
491
|
+
| 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. |
|
|
492
|
+
| 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. |
|
|
493
|
+
| getRelation(model, filterFunction) | To get all the objects respecting a specific relation with this object (see [model relations](#model-relations)). |
|
|
494
|
+
| save() | Method to save the object. You can do `store.save()` instead. |
|
|
495
|
+
| destroy() | Method to delete the object. You can do `store.delete()` instead. |
|
|
496
|
+
|
|
497
|
+
| toJSON() | It returns a pure JSON representation of the object. |
|
|
498
|
+
| toString() | It returns a string representation of the object. |
|
|
499
|
+
| 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. |
|
|
500
|
+
| 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
501
|
|
|
497
502
|
## Editing objects
|
|
498
503
|
The option `autoSave` can be `true`, `false`, or a number (milliseconds).
|
|
@@ -518,7 +523,7 @@ The option `autoSave` can be `true`, `false`, or a number (milliseconds).
|
|
|
518
523
|
|
|
519
524
|
The store will perform as if the `autoSave` was set to `true`; hence, changes performed with `.set(attribute, value)` are synced. However, it will periodically attempt also a `store.save()`. Since `store.save()` is always able to recognize edited objects, also changes directly operated on an attribute of the object (`object.name = "Dante"`) are synced.
|
|
520
525
|
|
|
521
|
-
|
|
526
|
+
> The method set takes 3 parameters in input, "attribute, value, hidden". The "hidden" parameter allows you to set an attribute to the object that will not trigger autoSave. However, hidden attributes cannot be persisted (they act like "hiddenFields" specified during model creation).
|
|
522
527
|
|
|
523
528
|
## API interaction
|
|
524
529
|
DataFlux is able to identify three sets of objects: inserted, updated, deleted.
|
package/dist/Model.js
CHANGED
|
@@ -19,14 +19,16 @@ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArra
|
|
|
19
19
|
|
|
20
20
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
21
|
|
|
22
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
23
|
-
|
|
24
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
25
|
-
|
|
26
22
|
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
27
23
|
|
|
28
24
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
29
25
|
|
|
26
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
27
|
+
|
|
28
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
+
|
|
30
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
31
|
+
|
|
30
32
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
31
33
|
|
|
32
34
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -87,12 +89,16 @@ var _axios = /*#__PURE__*/new WeakMap();
|
|
|
87
89
|
|
|
88
90
|
var _loadFunction = /*#__PURE__*/new WeakMap();
|
|
89
91
|
|
|
92
|
+
var _hiddenFields = /*#__PURE__*/new WeakMap();
|
|
93
|
+
|
|
90
94
|
var _error = /*#__PURE__*/new WeakSet();
|
|
91
95
|
|
|
92
96
|
var _addRelationByField = /*#__PURE__*/new WeakMap();
|
|
93
97
|
|
|
94
98
|
var _addRelationByFilter = /*#__PURE__*/new WeakMap();
|
|
95
99
|
|
|
100
|
+
var _removeHiddenFields = /*#__PURE__*/new WeakMap();
|
|
101
|
+
|
|
96
102
|
var _bulkOperation = /*#__PURE__*/new WeakMap();
|
|
97
103
|
|
|
98
104
|
var _toArray = /*#__PURE__*/new WeakMap();
|
|
@@ -167,6 +173,11 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
167
173
|
value: void 0
|
|
168
174
|
});
|
|
169
175
|
|
|
176
|
+
_classPrivateFieldInitSpec(this, _hiddenFields, {
|
|
177
|
+
writable: true,
|
|
178
|
+
value: void 0
|
|
179
|
+
});
|
|
180
|
+
|
|
170
181
|
_defineProperty(this, "getStore", function () {
|
|
171
182
|
return _classPrivateFieldGet(_this, _store);
|
|
172
183
|
});
|
|
@@ -293,16 +304,37 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
293
304
|
}
|
|
294
305
|
});
|
|
295
306
|
|
|
307
|
+
_classPrivateFieldInitSpec(this, _removeHiddenFields, {
|
|
308
|
+
writable: true,
|
|
309
|
+
value: function value(json) {
|
|
310
|
+
var _iterator = _createForOfIteratorHelper(_classPrivateFieldGet(_this, _hiddenFields)),
|
|
311
|
+
_step;
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
315
|
+
var attribute = _step.value;
|
|
316
|
+
delete json[attribute];
|
|
317
|
+
}
|
|
318
|
+
} catch (err) {
|
|
319
|
+
_iterator.e(err);
|
|
320
|
+
} finally {
|
|
321
|
+
_iterator.f();
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return json;
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
|
|
296
328
|
_classPrivateFieldInitSpec(this, _bulkOperation, {
|
|
297
329
|
writable: true,
|
|
298
330
|
value: function value(objects, action) {
|
|
299
331
|
if (_classPrivateFieldGet(_this, _singleItemQuery)) {
|
|
300
332
|
return (0, _batchPromises["default"])(_classPrivateFieldGet(_this, _batchSize), objects.map(function (i) {
|
|
301
|
-
return i.toJSON();
|
|
333
|
+
return _classPrivateFieldGet(_this, _removeHiddenFields).call(_this, i.toJSON());
|
|
302
334
|
}), action);
|
|
303
335
|
} else {
|
|
304
336
|
return action(objects.map(function (i) {
|
|
305
|
-
return i.toJSON();
|
|
337
|
+
return _classPrivateFieldGet(_this, _removeHiddenFields).call(_this, i.toJSON());
|
|
306
338
|
}));
|
|
307
339
|
}
|
|
308
340
|
}
|
|
@@ -352,6 +384,8 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
352
384
|
|
|
353
385
|
_classPrivateFieldSet(this, _axios, options.axios || _axios2["default"]);
|
|
354
386
|
|
|
387
|
+
_classPrivateFieldSet(this, _hiddenFields, options.hiddenFields || []);
|
|
388
|
+
|
|
355
389
|
_classPrivateFieldSet(this, _loadFunction, options.load || null);
|
|
356
390
|
|
|
357
391
|
if (!name || !options) {
|
package/dist/Obj.js
CHANGED
|
@@ -39,6 +39,8 @@ var dateRegex = new RegExp("^[0-9][0-9][0-9][0-9]-[0-9].*T[0-9].*Z$");
|
|
|
39
39
|
|
|
40
40
|
var _loaded = /*#__PURE__*/new WeakMap();
|
|
41
41
|
|
|
42
|
+
var _setHidden = /*#__PURE__*/new WeakMap();
|
|
43
|
+
|
|
42
44
|
var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
|
|
43
45
|
var _this = this;
|
|
44
46
|
|
|
@@ -49,6 +51,11 @@ var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
|
|
|
49
51
|
value: false
|
|
50
52
|
});
|
|
51
53
|
|
|
54
|
+
_classPrivateFieldInitSpec(this, _setHidden, {
|
|
55
|
+
writable: true,
|
|
56
|
+
value: {}
|
|
57
|
+
});
|
|
58
|
+
|
|
52
59
|
_defineProperty(this, "load", function () {
|
|
53
60
|
if (_classPrivateFieldGet(_this, _loaded)) {
|
|
54
61
|
return Promise.resolve(_this);
|
|
@@ -69,23 +76,36 @@ var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
|
|
|
69
76
|
return (0, _fingerprint["default"])(_this.toJSON());
|
|
70
77
|
});
|
|
71
78
|
|
|
72
|
-
_defineProperty(this, "get", function (attribute) {
|
|
73
|
-
|
|
79
|
+
_defineProperty(this, "get", function (attribute, defaultValue) {
|
|
80
|
+
var _ref, _classPrivateFieldGet2;
|
|
81
|
+
|
|
82
|
+
return (_ref = (_classPrivateFieldGet2 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : _this[attribute]) !== null && _ref !== void 0 ? _ref : defaultValue;
|
|
74
83
|
});
|
|
75
84
|
|
|
76
85
|
_defineProperty(this, "getRelation", function (type, filterFunction) {
|
|
77
86
|
return _this.getModel().getRelation(_this, type, filterFunction);
|
|
78
87
|
});
|
|
79
88
|
|
|
80
|
-
_defineProperty(this, "set", function (attribute, value) {
|
|
81
|
-
if (
|
|
82
|
-
|
|
89
|
+
_defineProperty(this, "set", function (attribute, value, hidden) {
|
|
90
|
+
if (hidden) {
|
|
91
|
+
_classPrivateFieldGet(_this, _setHidden)[attribute] = value;
|
|
92
|
+
} else {
|
|
93
|
+
if (attribute === "id") {
|
|
94
|
+
throw new Error("You cannot change the ID");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
_this[attribute] = value;
|
|
83
98
|
}
|
|
84
99
|
|
|
85
|
-
_this[attribute] = value;
|
|
86
100
|
return _this.getModel().getStore().update([_this]);
|
|
87
101
|
});
|
|
88
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
|
+
|
|
89
109
|
_defineProperty(this, "save", function () {
|
|
90
110
|
return _this.getModel().getStore().save([_this]);
|
|
91
111
|
});
|
package/dist/ObserverStore.js
CHANGED
|
@@ -15,19 +15,19 @@ var _PersistentStore2 = _interopRequireDefault(require("./PersistentStore"));
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
17
|
|
|
18
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(
|
|
18
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
19
19
|
|
|
20
|
-
function
|
|
20
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
21
21
|
|
|
22
|
-
function
|
|
22
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
23
23
|
|
|
24
24
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
25
|
|
|
26
|
-
function
|
|
26
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
27
27
|
|
|
28
|
-
function
|
|
28
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
29
29
|
|
|
30
|
-
function
|
|
30
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
31
31
|
|
|
32
32
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
33
33
|
|
|
@@ -92,13 +92,28 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
92
92
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _propagateInsertChange);
|
|
93
93
|
|
|
94
94
|
_defineProperty(_assertThisInitialized(_this), "multipleSubscribe", function (subscriptions, callback) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
var dataPayload = {};
|
|
96
|
+
|
|
97
|
+
var areAllDone = function areAllDone() {
|
|
98
|
+
return subscriptions.map(function (_ref) {
|
|
99
|
+
var _ref2 = _slicedToArray(_ref, 1),
|
|
100
|
+
name = _ref2[0];
|
|
101
|
+
|
|
102
|
+
return name;
|
|
103
|
+
}).every(function (name) {
|
|
104
|
+
return dataPayload[name] !== undefined;
|
|
98
105
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return Promise.all(subscriptions.map(function (sub, index) {
|
|
109
|
+
var _sub = _slicedToArray(sub, 2),
|
|
110
|
+
name = _sub[0],
|
|
111
|
+
_sub$ = _sub[1],
|
|
112
|
+
filterFunction = _sub$ === void 0 ? null : _sub$;
|
|
113
|
+
|
|
114
|
+
return _this.subscribe(name, filterFunction, function (data) {
|
|
115
|
+
dataPayload[name] = data;
|
|
116
|
+
return areAllDone() && callback(dataPayload);
|
|
102
117
|
});
|
|
103
118
|
})).then(function (subKeys) {
|
|
104
119
|
var subKey = (0, _uuid.v4)();
|
|
@@ -209,9 +224,9 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
209
224
|
|
|
210
225
|
var uniqueSubs = _classPrivateFieldGet(_assertThisInitialized(_this), _getUniqueSubs).call(_assertThisInitialized(_this), objects, type);
|
|
211
226
|
|
|
212
|
-
(0, _batchPromises["default"])(10, uniqueSubs, function (
|
|
213
|
-
var callback =
|
|
214
|
-
filterFunction =
|
|
227
|
+
(0, _batchPromises["default"])(10, uniqueSubs, function (_ref3) {
|
|
228
|
+
var callback = _ref3.callback,
|
|
229
|
+
filterFunction = _ref3.filterFunction;
|
|
215
230
|
return _this.find(type, filterFunction).then(callback);
|
|
216
231
|
});
|
|
217
232
|
}
|
|
@@ -284,8 +299,8 @@ function _propagateInsertChange2(type, newObjects) {
|
|
|
284
299
|
var uniqueSubs = {};
|
|
285
300
|
var objects = Object.values(this._subscribed[type]);
|
|
286
301
|
|
|
287
|
-
for (var
|
|
288
|
-
var object = _objects[
|
|
302
|
+
for (var _i2 = 0, _objects = objects; _i2 < _objects.length; _i2++) {
|
|
303
|
+
var object = _objects[_i2];
|
|
289
304
|
|
|
290
305
|
var _iterator5 = _createForOfIteratorHelper(object),
|
|
291
306
|
_step5;
|
|
@@ -306,9 +321,9 @@ function _propagateInsertChange2(type, newObjects) {
|
|
|
306
321
|
}
|
|
307
322
|
|
|
308
323
|
var possibleSubs = Object.values(uniqueSubs);
|
|
309
|
-
(0, _batchPromises["default"])(10, possibleSubs, function (
|
|
310
|
-
var callback =
|
|
311
|
-
filterFunction =
|
|
324
|
+
(0, _batchPromises["default"])(10, possibleSubs, function (_ref4) {
|
|
325
|
+
var callback = _ref4.callback,
|
|
326
|
+
filterFunction = _ref4.filterFunction;
|
|
312
327
|
var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
|
|
313
328
|
|
|
314
329
|
if (objectsToSubscribe.length) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataflux",
|
|
3
|
-
"version": "1.3
|
|
3
|
+
"version": "1.4.3",
|
|
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",
|