dataflux 1.5.5 → 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 +15 -14
- package/_config.yml +1 -0
- package/dist/ReactStore.js +53 -33
- package/dist/Store.js +5 -0
- package/package.json +6 -6
package/CNAME
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
dataflux.js.org
|
package/README.md
CHANGED
|
@@ -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:
|
package/_config.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
theme: jekyll-theme-cayman
|
package/dist/ReactStore.js
CHANGED
|
@@ -15,6 +15,12 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
15
15
|
|
|
16
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; }
|
|
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(_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
|
+
|
|
18
24
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
25
|
|
|
20
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); } }
|
|
@@ -39,42 +45,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
39
45
|
|
|
40
46
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
41
47
|
|
|
42
|
-
function
|
|
48
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
43
49
|
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
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; } } }; }
|
|
47
|
-
|
|
48
|
-
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); }
|
|
49
|
-
|
|
50
|
-
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; }
|
|
50
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
51
51
|
|
|
52
|
-
var
|
|
53
|
-
// I know...
|
|
54
|
-
context.___obs_subkeys = context.___obs_subkeys || [];
|
|
52
|
+
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
55
53
|
|
|
56
|
-
|
|
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); }
|
|
57
55
|
|
|
58
|
-
|
|
59
|
-
var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
|
|
60
|
-
_step;
|
|
56
|
+
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
61
57
|
|
|
62
|
-
|
|
63
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
64
|
-
var key = _step.value;
|
|
65
|
-
context.unsubscribe(key);
|
|
66
|
-
}
|
|
67
|
-
} catch (err) {
|
|
68
|
-
_iterator.e(err);
|
|
69
|
-
} finally {
|
|
70
|
-
_iterator.f();
|
|
71
|
-
}
|
|
72
|
-
};
|
|
58
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
73
59
|
|
|
74
|
-
|
|
75
|
-
context.___obs_unsubscribe();
|
|
76
|
-
};
|
|
77
|
-
};
|
|
60
|
+
var _addSubscriptionToContext = /*#__PURE__*/new WeakMap();
|
|
78
61
|
|
|
79
62
|
var _fixState = /*#__PURE__*/new WeakSet();
|
|
80
63
|
|
|
@@ -92,10 +75,45 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
|
|
|
92
75
|
|
|
93
76
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _fixState);
|
|
94
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);
|
|
87
|
+
|
|
88
|
+
context.___obs_unsubscribe = function () {
|
|
89
|
+
var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
|
|
90
|
+
_step;
|
|
91
|
+
|
|
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
|
+
|
|
95
111
|
_defineProperty(_assertThisInitialized(_this), "handleChange", function (object, name) {
|
|
96
112
|
return function (event, rawValue) {
|
|
113
|
+
var _ref;
|
|
114
|
+
|
|
97
115
|
var value = event ? event.target.type === "checkbox" ? event.target.checked : event.target.value : "";
|
|
98
|
-
object.set(name, value
|
|
116
|
+
object.set(name, (_ref = value !== null && value !== void 0 ? value : rawValue) !== null && _ref !== void 0 ? _ref : "");
|
|
99
117
|
};
|
|
100
118
|
});
|
|
101
119
|
|
|
@@ -110,7 +128,8 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
|
|
|
110
128
|
var subKey = this.subscribe(type, function (data) {
|
|
111
129
|
context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data || [])));
|
|
112
130
|
}, filterFunction);
|
|
113
|
-
|
|
131
|
+
|
|
132
|
+
_classPrivateFieldGet(this, _addSubscriptionToContext).call(this, context, subKey);
|
|
114
133
|
}
|
|
115
134
|
}, {
|
|
116
135
|
key: "findOne",
|
|
@@ -120,7 +139,8 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
|
|
|
120
139
|
var subKey = this.subscribe(type, function (data) {
|
|
121
140
|
context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data && data.length ? data[0] : null)));
|
|
122
141
|
}, filterFunction);
|
|
123
|
-
|
|
142
|
+
|
|
143
|
+
_classPrivateFieldGet(this, _addSubscriptionToContext).call(this, context, subKey);
|
|
124
144
|
}
|
|
125
145
|
}]);
|
|
126
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/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
|
},
|