dataflux 1.5.2 → 1.6.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/CNAME +1 -0
- package/README.md +58 -21
- package/_config.yml +1 -0
- package/dist/BasicObj.js +27 -3
- package/dist/Obj.js +3 -22
- package/dist/ReactStore.js +58 -41
- package/dist/Store.js +5 -0
- package/dist/SubObj.js +24 -22
- package/dist/fingerprint.js +4 -4
- package/package.json +6 -6
package/CNAME
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dataflux.js.org
|
package/README.md
CHANGED
|
@@ -87,7 +87,7 @@ Nothing else to do! After your edit, the store will do a single PUT request to t
|
|
|
87
87
|
|
|
88
88
|
### Example 2
|
|
89
89
|
|
|
90
|
-
DataFlux automatically sends the edited objects back to the API to be saved. However, you can disable this behavior and manually instruct the store when to save.
|
|
90
|
+
DataFlux automatically sends the edited objects back to the API to be saved. However, you can disable this behavior and manually instruct the store when to save.
|
|
91
91
|
|
|
92
92
|
```js
|
|
93
93
|
// To disable autoSave you must declare the store (in store.js) as follows
|
|
@@ -100,7 +100,7 @@ The same example above now becomes:
|
|
|
100
100
|
// Find the author Dante Alighieri
|
|
101
101
|
store.find("author", ({name, surname}) => name == "Dante" && surname == "Alighieri")
|
|
102
102
|
.then(([author]) => {
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
// When autoSave is false, author.set("country", "Italy") and
|
|
105
105
|
// author.country = "Italy" are equivalent
|
|
106
106
|
author.country = "Italy"
|
|
@@ -174,12 +174,12 @@ You can also do multiple subscriptions at once:
|
|
|
174
174
|
|
|
175
175
|
```js
|
|
176
176
|
const subscriptions = [
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
["book", ({title}) => title === "The little prince"], // Model name and filter function
|
|
178
|
+
["author"], // No filter function, all objects returned
|
|
179
179
|
];
|
|
180
180
|
|
|
181
181
|
const callback = ({book, author}) => {
|
|
182
|
-
|
|
182
|
+
// Objects are ready
|
|
183
183
|
};
|
|
184
184
|
|
|
185
185
|
const subKey = store.multipleSubscribe(requests, callback); // Subscribe
|
|
@@ -221,7 +221,7 @@ class MyComponent extends React.Component {
|
|
|
221
221
|
onTitleChange={(title) => book.set("title", title)}
|
|
222
222
|
// onTitleChange will alter the book and so the current
|
|
223
223
|
// state of "books" (a setState will be performed).
|
|
224
|
-
|
|
224
|
+
|
|
225
225
|
// Alternatively:
|
|
226
226
|
// onTitleChange={store.handleChange(book, "title")}
|
|
227
227
|
// is a syntactic sugar of the function above
|
|
@@ -456,20 +456,21 @@ author1.getRelation("book", (book) => book.price < 20)
|
|
|
456
456
|
|
|
457
457
|
The store has the following method.
|
|
458
458
|
|
|
459
|
-
| Method | Description
|
|
460
|
-
|
|
461
|
-
| on(event, callback) | Method to subscribe to the events emitted by the store. See [events](#store-events) below.
|
|
462
|
-
| addModel(model) | Introduce a new model to the store. If lazyLoad = false (default), the model is populated with the objects coming from the API.
|
|
463
|
-
| get(type, id) | It allows to retrieve an object based on its type and store's ID (see `getId()` in [objects methods](#objects-methods). The type is the name of the model.
|
|
464
|
-
| find(type, filterFunction) | The promise-oriented method to access objects given a type and a filter function. If the filter function is missing, all the objects are returned. See [example 1](#example-1).
|
|
465
|
-
| delete(objects) | It deletes an array of objects. See [example 1](#example-3).
|
|
466
|
-
| delete(type, filterFunction) | It deleted objects given an array and a filter function. See [example 1](#example-3).
|
|
467
|
-
| insert(type, object) | It creates a new object of a given type and inserts it in the store.
|
|
468
|
-
| subscribe(type, callback, filterFunction) | The callback-oriented method to access objects given a type and a filter function. It returns the key of the subscription, needed to unsubscribe. If the filter function is missing, all the objects are returned. **DataFlux remembers your query and calls the callback every time any change is affecting the result of your query.** See [example 5](#example-5---observability).
|
|
469
|
-
| multipleSubscribe(subscriptions, callback) | A method to subscribe to multiple models. The first parameter is an array of models' names and filterFunctions, the second parameter is the callback to be called when the cumulative dataset is ready. E.g., `multipleSubscribe([["book", filterFunction1], ["author", filterFunction2]], callback)`. It returns the key of the subscription. See [example 5](#example-5---observability).
|
|
470
|
-
| unsubscribe(key) | Method to terminate a subscription given a subscription key. See [example 5](#example-5---observability).
|
|
471
|
-
| findOne(type, stateAttribute, context, filterFunction) | This method automatically injects and updates the React state with the requested data. If multiple objects satisfy the query, only the first is selected. The `stateAttribute` is the name of the attribute that will be added/updated in the state, the `context` is the React.Component. It automatically unsubscribe when the React.Component will unmount. See [example 6](#example-6---observability--react).
|
|
472
|
-
| findAll(type, stateAttribute, context, filterFunction) | This method automatically injects and updates the React state with the requested data. The `stateAttribute` is the name of the attribute that will be added/updated in the state, the `context` is the React.Component. It automatically unsubscribe when the React.Component will unmount. If the filter function is missing, all the objects are returned. See [example 6](#example-6---observability--react).
|
|
459
|
+
| Method | Description |
|
|
460
|
+
|--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
461
|
+
| on(event, callback) | Method to subscribe to the events emitted by the store. See [events](#store-events) below. |
|
|
462
|
+
| addModel(model) | Introduce a new model to the store. If lazyLoad = false (default), the model is populated with the objects coming from the API. |
|
|
463
|
+
| get(type, id) | It allows to retrieve an object based on its type and store's ID (see `getId()` in [objects methods](#objects-methods). The type is the name of the model. |
|
|
464
|
+
| find(type, filterFunction) | The promise-oriented method to access objects given a type and a filter function. If the filter function is missing, all the objects are returned. See [example 1](#example-1). |
|
|
465
|
+
| delete(objects) | It deletes an array of objects. See [example 1](#example-3). |
|
|
466
|
+
| delete(type, filterFunction) | It deleted objects given an array and a filter function. See [example 1](#example-3). |
|
|
467
|
+
| insert(type, object) | It creates a new object of a given type and inserts it in the store. |
|
|
468
|
+
| subscribe(type, callback, filterFunction) | The callback-oriented method to access objects given a type and a filter function. It returns the key of the subscription, needed to unsubscribe. If the filter function is missing, all the objects are returned. **DataFlux remembers your query and calls the callback every time any change is affecting the result of your query.** See [example 5](#example-5---observability). |
|
|
469
|
+
| multipleSubscribe(subscriptions, callback) | A method to subscribe to multiple models. The first parameter is an array of models' names and filterFunctions, the second parameter is the callback to be called when the cumulative dataset is ready. E.g., `multipleSubscribe([["book", filterFunction1], ["author", filterFunction2]], callback)`. It returns the key of the subscription. See [example 5](#example-5---observability). |
|
|
470
|
+
| unsubscribe(key) | Method to terminate a subscription given a subscription key. See [example 5](#example-5---observability). |
|
|
471
|
+
| findOne(type, stateAttribute, context, filterFunction) | This method automatically injects and updates the React state with the requested data. If multiple objects satisfy the query, only the first is selected. The `stateAttribute` is the name of the attribute that will be added/updated in the state, the `context` is the React.Component. It automatically unsubscribe when the React.Component will unmount. See [example 6](#example-6---observability--react). |
|
|
472
|
+
| findAll(type, stateAttribute, context, filterFunction) | This method automatically injects and updates the React state with the requested data. The `stateAttribute` is the name of the attribute that will be added/updated in the state, the `context` is the React.Component. It automatically unsubscribe when the React.Component will unmount. If the filter function is missing, all the objects are returned. See [example 6](#example-6---observability--react). |
|
|
473
|
+
| preload(type) | This method allows to preLoad all objects of a given model. If you initialize the store with `lazyLoad:true`, the objects of a model are retrieved from the API at the first query performed on that model (e.g., at the first `.find()`). However, sometimes you may want to speed up the first query by pre loading the objects of a specific model while keeping `lazyLoad:true` on the store; in such a case you can use `store.preload(type)`. |
|
|
473
474
|
|
|
474
475
|
## Store events
|
|
475
476
|
The store emits the following events:
|
|
@@ -493,11 +494,47 @@ Each object created is enriched with the following methods.
|
|
|
493
494
|
| getRelation(model, filterFunction) | To get all the objects respecting a specific relation with this object (see [model relations](#model-relations)). |
|
|
494
495
|
| save() | Method to save the object. You can do `store.save()` instead. |
|
|
495
496
|
| destroy() | Method to delete the object. You can do `store.delete()` instead. |
|
|
496
|
-
|
|
497
497
|
| toJSON() | It returns a pure JSON representation of the object. |
|
|
498
498
|
| toString() | It returns a string representation of the object. |
|
|
499
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
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. |
|
|
501
|
+
### Deeper Objects
|
|
502
|
+
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.
|
|
503
|
+
|
|
504
|
+
Imagine the API returns:
|
|
505
|
+
|
|
506
|
+
```json
|
|
507
|
+
[
|
|
508
|
+
{
|
|
509
|
+
"title": "The little prince",
|
|
510
|
+
"reviews": [
|
|
511
|
+
{
|
|
512
|
+
"stars": 4,
|
|
513
|
+
"comment": "comment 1"
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
"stars": 3,
|
|
517
|
+
"comment": "comment 2"
|
|
518
|
+
}
|
|
519
|
+
]
|
|
520
|
+
},
|
|
521
|
+
...
|
|
522
|
+
]
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
You can operate on the reviews similarly to how you operate on the main model's objects (book).
|
|
526
|
+
|
|
527
|
+
```js
|
|
528
|
+
store.find("book")
|
|
529
|
+
.then(([book]) => {
|
|
530
|
+
const firstReview = book.reviews[0];
|
|
531
|
+
|
|
532
|
+
// Examples of what you can do:
|
|
533
|
+
firstReview.detroy(); // The first review is removed from the array book.reviews
|
|
534
|
+
firstReview.set("stars", 5); // Set the stars of the first review to 5
|
|
535
|
+
});
|
|
536
|
+
```
|
|
537
|
+
|
|
501
538
|
|
|
502
539
|
## Editing objects
|
|
503
540
|
The option `autoSave` can be `true`, `false`, or a number (milliseconds).
|
package/_config.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
theme: jekyll-theme-cayman
|
package/dist/BasicObj.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.dateRegex = exports.BasicObj = void 0;
|
|
7
|
+
exports.setValues = setValues;
|
|
7
8
|
|
|
8
9
|
var _moment = _interopRequireDefault(require("moment/moment"));
|
|
9
10
|
|
|
@@ -33,9 +34,30 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
|
|
|
33
34
|
|
|
34
35
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
35
36
|
|
|
37
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
38
|
+
|
|
36
39
|
var dateRegex = new RegExp("^[0-9][0-9][0-9][0-9]-[0-9].*T[0-9].*Z$");
|
|
37
40
|
exports.dateRegex = dateRegex;
|
|
38
41
|
|
|
42
|
+
function setValues(values, model, SubObj, parent, context) {
|
|
43
|
+
Object.keys(values).forEach(function (key) {
|
|
44
|
+
var value = values[key];
|
|
45
|
+
|
|
46
|
+
if (model.options.parseMoment && value != null && dateRegex.test(value)) {
|
|
47
|
+
var mmnt = (0, _moment["default"])(value);
|
|
48
|
+
context[key] = mmnt.isValid() ? mmnt : value;
|
|
49
|
+
} else if (model.options.deep && value != null && _typeof(value) === "object" && !Array.isArray(value)) {
|
|
50
|
+
context[key] = new SubObj(parent, key, value, model);
|
|
51
|
+
} else if (model.options.deep && value != null && Array.isArray(value)) {
|
|
52
|
+
context[key] = value.map(function (i) {
|
|
53
|
+
return new SubObj(parent, key, i, model);
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
context[key] = value;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
39
61
|
var _setHidden = /*#__PURE__*/new WeakMap();
|
|
40
62
|
|
|
41
63
|
var _id = /*#__PURE__*/new WeakMap();
|
|
@@ -100,14 +122,16 @@ var BasicObj = /*#__PURE__*/_createClass(function BasicObj(values, model) {
|
|
|
100
122
|
for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
|
|
101
123
|
var a = _attrs[_i];
|
|
102
124
|
|
|
103
|
-
if (_this[a]
|
|
125
|
+
if (_this[a] == null) {
|
|
126
|
+
out[a] = _this[a];
|
|
127
|
+
} else if (_this[a] instanceof _moment["default"]) {
|
|
104
128
|
out[a] = _this[a].toISOString();
|
|
105
129
|
} else if (_this[a] instanceof Date) {
|
|
106
130
|
out[a] = (0, _moment["default"])(_this[a]).toISOString();
|
|
107
|
-
} else if (_this[a].toJSON) {
|
|
131
|
+
} else if (_typeof(_this[a]) === "object" && _this[a].toJSON) {
|
|
108
132
|
out[a] = _this[a].toJSON();
|
|
109
133
|
} else if (Array.isArray(_this[a]) && _this[a].every(function (i) {
|
|
110
|
-
return i.toJSON;
|
|
134
|
+
return _typeof(i) === "object" && i.toJSON;
|
|
111
135
|
})) {
|
|
112
136
|
out[a] = _this[a].map(function (i) {
|
|
113
137
|
return i.toJSON();
|
package/dist/Obj.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
@@ -7,18 +9,12 @@ exports["default"] = void 0;
|
|
|
7
9
|
|
|
8
10
|
var _fingerprint = _interopRequireDefault(require("./fingerprint"));
|
|
9
11
|
|
|
10
|
-
var _uuid = require("uuid");
|
|
11
|
-
|
|
12
12
|
var _BasicObj2 = require("./BasicObj");
|
|
13
13
|
|
|
14
|
-
var _moment = _interopRequireDefault(require("moment/moment"));
|
|
15
|
-
|
|
16
14
|
var _SubObj = _interopRequireDefault(require("./SubObj"));
|
|
17
15
|
|
|
18
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
17
|
|
|
20
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
21
|
-
|
|
22
18
|
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); } }
|
|
23
19
|
|
|
24
20
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -110,22 +106,7 @@ var Obj = /*#__PURE__*/function (_BasicObj) {
|
|
|
110
106
|
return _this.getModel().getStore().update([_assertThisInitialized(_this)]);
|
|
111
107
|
});
|
|
112
108
|
|
|
113
|
-
|
|
114
|
-
var value = values[key];
|
|
115
|
-
|
|
116
|
-
if (_model.options.parseMoment && _BasicObj2.dateRegex.test(value)) {
|
|
117
|
-
var mmnt = (0, _moment["default"])(value);
|
|
118
|
-
_this[key] = mmnt.isValid() ? mmnt : value;
|
|
119
|
-
} else if (_model.options.deep && _typeof(value) === "object" && !Array.isArray(value)) {
|
|
120
|
-
_this[key] = new _SubObj["default"](_assertThisInitialized(_this), value, _model);
|
|
121
|
-
} else if (_model.options.deep && Array.isArray(value)) {
|
|
122
|
-
_this[key] = value.map(function (i) {
|
|
123
|
-
return new _SubObj["default"](_assertThisInitialized(_this), i, _model);
|
|
124
|
-
});
|
|
125
|
-
} else {
|
|
126
|
-
_this[key] = value;
|
|
127
|
-
}
|
|
128
|
-
});
|
|
109
|
+
(0, _BasicObj2.setValues)(values, _model, _SubObj["default"], _assertThisInitialized(_this), _assertThisInitialized(_this));
|
|
129
110
|
|
|
130
111
|
_this.getModel = function () {
|
|
131
112
|
return _model;
|
package/dist/ReactStore.js
CHANGED
|
@@ -9,14 +9,18 @@ exports["default"] = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _ObserverStore2 = _interopRequireDefault(require("./ObserverStore"));
|
|
11
11
|
|
|
12
|
-
var _this = void 0;
|
|
13
|
-
|
|
14
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
13
|
|
|
16
14
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
15
|
|
|
18
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
19
|
+
|
|
20
|
+
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); }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
20
24
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
21
25
|
|
|
22
26
|
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); } }
|
|
@@ -41,43 +45,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
41
45
|
|
|
42
46
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
43
47
|
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
47
|
-
|
|
48
|
-
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(_e) { throw _e; }, 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(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
49
|
-
|
|
50
|
-
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); }
|
|
51
|
-
|
|
52
|
-
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; }
|
|
48
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
// I know...
|
|
56
|
-
context.___obs_subkeys = context.___obs_subkeys || [];
|
|
50
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
57
51
|
|
|
58
|
-
|
|
52
|
+
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
59
53
|
|
|
60
|
-
|
|
61
|
-
var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
|
|
62
|
-
_step;
|
|
54
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
63
55
|
|
|
64
|
-
|
|
65
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
66
|
-
var key = _step.value;
|
|
56
|
+
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
67
57
|
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
} catch (err) {
|
|
71
|
-
_iterator.e(err);
|
|
72
|
-
} finally {
|
|
73
|
-
_iterator.f();
|
|
74
|
-
}
|
|
75
|
-
};
|
|
58
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
76
59
|
|
|
77
|
-
|
|
78
|
-
context.___obs_unsubscribe();
|
|
79
|
-
};
|
|
80
|
-
};
|
|
60
|
+
var _addSubscriptionToContext = /*#__PURE__*/new WeakMap();
|
|
81
61
|
|
|
82
62
|
var _fixState = /*#__PURE__*/new WeakSet();
|
|
83
63
|
|
|
@@ -87,22 +67,57 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
|
|
|
87
67
|
var _super = _createSuper(ReactStore);
|
|
88
68
|
|
|
89
69
|
function ReactStore(options) {
|
|
90
|
-
var
|
|
70
|
+
var _this;
|
|
91
71
|
|
|
92
72
|
_classCallCheck(this, ReactStore);
|
|
93
73
|
|
|
94
|
-
|
|
74
|
+
_this = _super.call(this, options);
|
|
75
|
+
|
|
76
|
+
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _fixState);
|
|
77
|
+
|
|
78
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _addSubscriptionToContext, {
|
|
79
|
+
writable: true,
|
|
80
|
+
value: function value(context, subKey) {
|
|
81
|
+
// I know...
|
|
82
|
+
context.___obs_subkeys = context.___obs_subkeys || [];
|
|
83
|
+
|
|
84
|
+
context.___obs_subkeys.push(subKey);
|
|
85
|
+
|
|
86
|
+
context.___obs_unsubscribe_context = _assertThisInitialized(_this);
|
|
95
87
|
|
|
96
|
-
|
|
88
|
+
context.___obs_unsubscribe = function () {
|
|
89
|
+
var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
|
|
90
|
+
_step;
|
|
97
91
|
|
|
98
|
-
|
|
92
|
+
try {
|
|
93
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
94
|
+
var key = _step.value;
|
|
95
|
+
|
|
96
|
+
context.___obs_unsubscribe_context.unsubscribe(key);
|
|
97
|
+
}
|
|
98
|
+
} catch (err) {
|
|
99
|
+
_iterator.e(err);
|
|
100
|
+
} finally {
|
|
101
|
+
_iterator.f();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
context.componentWillUnmount = function () {
|
|
106
|
+
context.___obs_unsubscribe();
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
_defineProperty(_assertThisInitialized(_this), "handleChange", function (object, name) {
|
|
99
112
|
return function (event, rawValue) {
|
|
113
|
+
var _ref;
|
|
114
|
+
|
|
100
115
|
var value = event ? event.target.type === "checkbox" ? event.target.checked : event.target.value : "";
|
|
101
|
-
object.set(name, value
|
|
116
|
+
object.set(name, (_ref = value !== null && value !== void 0 ? value : rawValue) !== null && _ref !== void 0 ? _ref : "");
|
|
102
117
|
};
|
|
103
118
|
});
|
|
104
119
|
|
|
105
|
-
return
|
|
120
|
+
return _this;
|
|
106
121
|
}
|
|
107
122
|
|
|
108
123
|
_createClass(ReactStore, [{
|
|
@@ -113,7 +128,8 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
|
|
|
113
128
|
var subKey = this.subscribe(type, function (data) {
|
|
114
129
|
context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data || [])));
|
|
115
130
|
}, filterFunction);
|
|
116
|
-
|
|
131
|
+
|
|
132
|
+
_classPrivateFieldGet(this, _addSubscriptionToContext).call(this, context, subKey);
|
|
117
133
|
}
|
|
118
134
|
}, {
|
|
119
135
|
key: "findOne",
|
|
@@ -123,7 +139,8 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
|
|
|
123
139
|
var subKey = this.subscribe(type, function (data) {
|
|
124
140
|
context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data && data.length ? data[0] : null)));
|
|
125
141
|
}, filterFunction);
|
|
126
|
-
|
|
142
|
+
|
|
143
|
+
_classPrivateFieldGet(this, _addSubscriptionToContext).call(this, context, subKey);
|
|
127
144
|
}
|
|
128
145
|
}]);
|
|
129
146
|
|
package/dist/Store.js
CHANGED
|
@@ -255,6 +255,11 @@ var Store = /*#__PURE__*/function () {
|
|
|
255
255
|
var obj = this.models[type].storedObjects[object.getId()];
|
|
256
256
|
return obj.fingerprint !== obj.object.getFingerprint();
|
|
257
257
|
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "preload",
|
|
260
|
+
value: function preload(type) {
|
|
261
|
+
return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type);
|
|
262
|
+
}
|
|
258
263
|
}, {
|
|
259
264
|
key: "getDiff",
|
|
260
265
|
value: function getDiff(type) {
|
package/dist/SubObj.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
|
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
|
4
6
|
value: true
|
|
5
7
|
});
|
|
6
8
|
exports["default"] = void 0;
|
|
7
9
|
|
|
8
|
-
var _uuid = require("uuid");
|
|
9
|
-
|
|
10
10
|
var _BasicObj2 = require("./BasicObj");
|
|
11
11
|
|
|
12
12
|
var _moment = _interopRequireDefault(require("moment/moment"));
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
15
|
|
|
16
|
-
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
17
|
-
|
|
18
16
|
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); } }
|
|
19
17
|
|
|
20
18
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -55,12 +53,14 @@ var _model = /*#__PURE__*/new WeakMap();
|
|
|
55
53
|
|
|
56
54
|
var _parent = /*#__PURE__*/new WeakMap();
|
|
57
55
|
|
|
56
|
+
var _parentField = /*#__PURE__*/new WeakMap();
|
|
57
|
+
|
|
58
58
|
var SubObj = /*#__PURE__*/function (_BasicObj) {
|
|
59
59
|
_inherits(SubObj, _BasicObj);
|
|
60
60
|
|
|
61
61
|
var _super = _createSuper(SubObj);
|
|
62
62
|
|
|
63
|
-
function SubObj(parent, values, model) {
|
|
63
|
+
function SubObj(parent, field, values, model) {
|
|
64
64
|
var _this;
|
|
65
65
|
|
|
66
66
|
_classCallCheck(this, SubObj);
|
|
@@ -77,12 +77,27 @@ var SubObj = /*#__PURE__*/function (_BasicObj) {
|
|
|
77
77
|
value: void 0
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _parentField, {
|
|
81
|
+
writable: true,
|
|
82
|
+
value: void 0
|
|
83
|
+
});
|
|
84
|
+
|
|
80
85
|
_defineProperty(_assertThisInitialized(_this), "save", function () {
|
|
81
86
|
return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore().save([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
|
|
82
87
|
});
|
|
83
88
|
|
|
84
89
|
_defineProperty(_assertThisInitialized(_this), "destroy", function () {
|
|
85
|
-
|
|
90
|
+
var _classPrivateFieldGet2;
|
|
91
|
+
|
|
92
|
+
if (Array.isArray(_classPrivateFieldGet(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)])) {
|
|
93
|
+
_classPrivateFieldGet(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)] = _classPrivateFieldGet(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)].filter(function (i) {
|
|
94
|
+
return i.getId() !== _this.getId();
|
|
95
|
+
});
|
|
96
|
+
} else if ((_classPrivateFieldGet2 = _classPrivateFieldGet(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)]) !== null && _classPrivateFieldGet2 !== void 0 && _classPrivateFieldGet2.getId) {
|
|
97
|
+
_classPrivateFieldGet(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)] = null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore().update([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
|
|
86
101
|
});
|
|
87
102
|
|
|
88
103
|
_defineProperty(_assertThisInitialized(_this), "update", function () {
|
|
@@ -93,22 +108,9 @@ var SubObj = /*#__PURE__*/function (_BasicObj) {
|
|
|
93
108
|
|
|
94
109
|
_classPrivateFieldSet(_assertThisInitialized(_this), _parent, parent);
|
|
95
110
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (model.options.parseMoment && _BasicObj2.dateRegex.test(value)) {
|
|
100
|
-
var mmnt = (0, _moment["default"])(value);
|
|
101
|
-
_this[key] = mmnt.isValid() ? mmnt : value;
|
|
102
|
-
} else if (model.options.deep && _typeof(value) === "object" && !Array.isArray(value)) {
|
|
103
|
-
_this[key] = new SubObj(_classPrivateFieldGet(_assertThisInitialized(_this), _parent), value, model);
|
|
104
|
-
} else if (model.options.deep && Array.isArray(value)) {
|
|
105
|
-
_this[key] = value.map(function (i) {
|
|
106
|
-
return new SubObj(_classPrivateFieldGet(_assertThisInitialized(_this), _parent), i, model);
|
|
107
|
-
});
|
|
108
|
-
} else {
|
|
109
|
-
_this[key] = value;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
111
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _parentField, field);
|
|
112
|
+
|
|
113
|
+
(0, _BasicObj2.setValues)(values, model, SubObj, _classPrivateFieldGet(_assertThisInitialized(_this), _parent), _assertThisInitialized(_this));
|
|
112
114
|
return _this;
|
|
113
115
|
}
|
|
114
116
|
|
package/dist/fingerprint.js
CHANGED
|
@@ -22,14 +22,14 @@ var CRC32 = require('crc-32');
|
|
|
22
22
|
var _getFingerprint = function _getFingerprint(object) {
|
|
23
23
|
switch (_typeof(object)) {
|
|
24
24
|
case "object":
|
|
25
|
-
if (object
|
|
25
|
+
if (object == null) {
|
|
26
|
+
return "o:null";
|
|
27
|
+
} else if (object._isAMomentObject) {
|
|
26
28
|
return "m:".concat(object.toISOString());
|
|
27
29
|
} else if (object instanceof Date) {
|
|
28
30
|
return "m:".concat((0, _moment["default"])(object).toISOString());
|
|
29
|
-
} else if (object !== null) {
|
|
30
|
-
return "o:".concat(getObjectFingerprint(object));
|
|
31
31
|
} else {
|
|
32
|
-
return "o:
|
|
32
|
+
return "o:".concat(getObjectFingerprint(object));
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
case "boolean":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataflux",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
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",
|
|
@@ -77,16 +77,16 @@
|
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
79
|
"devDependencies": {
|
|
80
|
-
"@babel/cli": "^7.
|
|
81
|
-
"@babel/core": "^7.
|
|
80
|
+
"@babel/cli": "^7.17.0",
|
|
81
|
+
"@babel/core": "^7.17.0",
|
|
82
82
|
"@babel/node": "^7.16.8",
|
|
83
83
|
"@babel/plugin-proposal-class-properties": "^7.16.7",
|
|
84
84
|
"@babel/plugin-proposal-object-rest-spread": "^7.16.7",
|
|
85
85
|
"@babel/plugin-transform-async-to-generator": "^7.16.8",
|
|
86
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
86
|
+
"@babel/plugin-transform-runtime": "^7.17.0",
|
|
87
87
|
"@babel/preset-env": "^7.16.11",
|
|
88
88
|
"@babel/preset-react": "^7.16.7",
|
|
89
|
-
"chai": "^4.3.
|
|
89
|
+
"chai": "^4.3.6",
|
|
90
90
|
"chai-subset": "^1.6.0",
|
|
91
91
|
"dotenv-cli": "^4.1.1",
|
|
92
92
|
"mocha": "^9.2.0",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"axios": "^0.25.0",
|
|
97
97
|
"batch-promises": "^0.0.3",
|
|
98
98
|
"brembo": "^2.0.6",
|
|
99
|
-
"crc-32": "^1.2.
|
|
99
|
+
"crc-32": "^1.2.1",
|
|
100
100
|
"moment": "^2.29.1",
|
|
101
101
|
"uuid": "^8.3.2"
|
|
102
102
|
},
|