dataflux 1.7.2 → 1.8.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 +38 -6
- package/dist/Model.js +31 -17
- package/dist/ObserverStore.js +127 -99
- package/dist/dataflux.min.js +2 -0
- package/dist/dataflux.min.js.map +1 -0
- package/dist/modelHooksUtils.js +31 -6
- package/package.json +10 -6
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npm install dataflux
|
|
|
20
20
|
|
|
21
21
|
Using jsDelivr CDN:
|
|
22
22
|
```html
|
|
23
|
-
<script src="https://cdn.jsdelivr.net/npm/dataflux/dist/
|
|
23
|
+
<script src="https://cdn.jsdelivr.net/npm/dataflux/dist/dataflux.min.js"></script>
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
## Examples
|
|
@@ -31,7 +31,7 @@ Consider the following hypothetical store/model declaration common to all the ex
|
|
|
31
31
|
|
|
32
32
|
```js
|
|
33
33
|
// Content of your store.js
|
|
34
|
-
|
|
34
|
+
const {Store, Model} = require("dataflux");
|
|
35
35
|
|
|
36
36
|
// We create a new Store
|
|
37
37
|
const store = new Store();
|
|
@@ -182,7 +182,7 @@ const callback = ({book, author}) => {
|
|
|
182
182
|
// Objects are ready
|
|
183
183
|
};
|
|
184
184
|
|
|
185
|
-
const subKey = store.multipleSubscribe(
|
|
185
|
+
const subKey = store.multipleSubscribe(subscriptions, callback); // Subscribe
|
|
186
186
|
|
|
187
187
|
store.unsubscribe(subKey); // Unsubscribe
|
|
188
188
|
```
|
|
@@ -205,8 +205,8 @@ class MyComponent extends React.Component {
|
|
|
205
205
|
// Get all books with a price < 20
|
|
206
206
|
store.findAll("book", "books", this, ({price}) => price < 20);
|
|
207
207
|
// An attribute "books" will be added/updated in the
|
|
208
|
-
// state
|
|
209
|
-
//
|
|
208
|
+
// state every time a book in our selection is inserted/deleted/edited,
|
|
209
|
+
// the rest of the state remains unchanged.
|
|
210
210
|
|
|
211
211
|
// findAll is a syntactic sugar for:
|
|
212
212
|
// const callback = (books) => {this.setState({...this.state, books})};
|
|
@@ -234,6 +234,25 @@ The method `findAll` returns always an array. The method `findOne` returns a sin
|
|
|
234
234
|
|
|
235
235
|
When the component will unmount, the `findAll` subscription will be automatically terminated without the need to unsubscribe. Be aware, `store.findAll()` injects the unsubscribe call inside `componentWillUnmount()`. If your component already implements `componentWillUnmount()`, then you will have to use `store.subscribe()` and `store.unsubscribe()` instead of `store.findAll()`, to avoid side effects when the component is unmounted.
|
|
236
236
|
|
|
237
|
+
In case you prefer React hooks:
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
function MyComponent() {
|
|
241
|
+
const [books, setBooks] = useState([]);
|
|
242
|
+
|
|
243
|
+
useEffect(() => {
|
|
244
|
+
const subKey = store.subscribe("books", setBooks, ({price}) => price < 20);
|
|
245
|
+
|
|
246
|
+
return () => {
|
|
247
|
+
store.unsubscribe(subKey); // Remember to unsubscribe
|
|
248
|
+
};
|
|
249
|
+
}, []);
|
|
250
|
+
|
|
251
|
+
return books.map(book => <Book onTitleChange={(title) => book.set("title", title)}/>);
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
|
|
237
256
|
## Configuration
|
|
238
257
|
|
|
239
258
|
The store can be configured with the following options:
|
|
@@ -289,10 +308,23 @@ An operation object is an object like follows:
|
|
|
289
308
|
{
|
|
290
309
|
"method": "get",
|
|
291
310
|
"url": "https://api.example.com",
|
|
292
|
-
"headers": {
|
|
311
|
+
"headers": {
|
|
312
|
+
"Authorization": "bearer XXXX"
|
|
313
|
+
},
|
|
314
|
+
"batch": false
|
|
293
315
|
}
|
|
294
316
|
```
|
|
295
317
|
|
|
318
|
+
Possible parameters are:
|
|
319
|
+
|
|
320
|
+
| Parameter | Description | Default |
|
|
321
|
+
|-----------|--------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
|
|
322
|
+
| method | HTTP method, accepted are get,post,put, and delete | "get" for retrieve, "post" for insert, "put" for update, and "delete" for delete |
|
|
323
|
+
| url | The url of the api | |
|
|
324
|
+
| headers | Headers for the HTTP request ([list](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields)). |
|
|
325
|
+
| batch | A boolean declaring if the API is able to receive an array of objects or an object at a time. This is not applicable for `retrieve`. | false |
|
|
326
|
+
|
|
327
|
+
|
|
296
328
|
Usage example:
|
|
297
329
|
|
|
298
330
|
```js
|
package/dist/Model.js
CHANGED
|
@@ -7,8 +7,6 @@ exports["default"] = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _modelHooksUtils = require("./modelHooksUtils");
|
|
9
9
|
|
|
10
|
-
var _batchPromises = _interopRequireDefault(require("batch-promises"));
|
|
11
|
-
|
|
12
10
|
var _axios2 = _interopRequireDefault(require("axios"));
|
|
13
11
|
|
|
14
12
|
var _BasicObj = require("./BasicObj");
|
|
@@ -99,6 +97,8 @@ var _bulkOperation = /*#__PURE__*/new WeakMap();
|
|
|
99
97
|
|
|
100
98
|
var _toArray = /*#__PURE__*/new WeakMap();
|
|
101
99
|
|
|
100
|
+
var _unWrap = /*#__PURE__*/new WeakMap();
|
|
101
|
+
|
|
102
102
|
var _insertObjects = /*#__PURE__*/new WeakMap();
|
|
103
103
|
|
|
104
104
|
var _updateObjects = /*#__PURE__*/new WeakMap();
|
|
@@ -193,7 +193,8 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
193
193
|
return _this.getStore().whenSaved(_this.getType())["catch"](function (e) {
|
|
194
194
|
throw new Error("You cannot perform load() on an unsaved object.");
|
|
195
195
|
}).then(function () {
|
|
196
|
-
var res = _classPrivateFieldGet(_this, _loadFunction).call(_this, obj.toJSON());
|
|
196
|
+
var res = _classPrivateFieldGet(_this, _loadFunction).call(_this, obj.toJSON()); // toJSON to avoid side effects;
|
|
197
|
+
|
|
197
198
|
|
|
198
199
|
if (typeof res === "string") {
|
|
199
200
|
return _classPrivateFieldGet(_this, _axios).call(_this, {
|
|
@@ -284,7 +285,13 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
284
285
|
if (!_this.options.lazyLoad) {
|
|
285
286
|
return Promise.reject("Factory can be used only on a model declared with lazyLoad: true");
|
|
286
287
|
} else {
|
|
287
|
-
return (0, _modelHooksUtils.executeHook)("retrieve", _classPrivateFieldGet(_this, _retrieveHook), params, _classPrivateFieldGet(_this, _axios))
|
|
288
|
+
return (0, _modelHooksUtils.executeHook)("retrieve", _classPrivateFieldGet(_this, _retrieveHook), params, _classPrivateFieldGet(_this, _axios)).then(function (data) {
|
|
289
|
+
if (!Array.isArray(data)) {
|
|
290
|
+
_classPrivateFieldSet(_this, _singleItemQuery, true);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return _classPrivateFieldGet(_this, _toArray).call(_this, data);
|
|
294
|
+
});
|
|
288
295
|
}
|
|
289
296
|
});
|
|
290
297
|
|
|
@@ -333,15 +340,9 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
333
340
|
_classPrivateFieldInitSpec(this, _bulkOperation, {
|
|
334
341
|
writable: true,
|
|
335
342
|
value: function value(objects, action) {
|
|
336
|
-
|
|
337
|
-
return (
|
|
338
|
-
|
|
339
|
-
}), action);
|
|
340
|
-
} else {
|
|
341
|
-
return action(objects.map(function (i) {
|
|
342
|
-
return _classPrivateFieldGet(_this, _removeHiddenFields).call(_this, i.toJSON());
|
|
343
|
-
}));
|
|
344
|
-
}
|
|
343
|
+
return action(objects.map(function (i) {
|
|
344
|
+
return _classPrivateFieldGet(_this, _removeHiddenFields).call(_this, i.toJSON());
|
|
345
|
+
}));
|
|
345
346
|
}
|
|
346
347
|
});
|
|
347
348
|
|
|
@@ -349,7 +350,7 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
349
350
|
writable: true,
|
|
350
351
|
value: function value(data) {
|
|
351
352
|
if (Array.isArray(data)) {
|
|
352
|
-
if (data.every(function (str) {
|
|
353
|
+
if (data.length && data.every(function (str) {
|
|
353
354
|
return ["string", "number"].includes(_typeof(str));
|
|
354
355
|
})) {
|
|
355
356
|
return [{
|
|
@@ -370,24 +371,37 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
370
371
|
}
|
|
371
372
|
});
|
|
372
373
|
|
|
374
|
+
_classPrivateFieldInitSpec(this, _unWrap, {
|
|
375
|
+
writable: true,
|
|
376
|
+
value: function value(data) {
|
|
377
|
+
if (data.value != null && Object.keys(data).length === 1) {
|
|
378
|
+
return data.value;
|
|
379
|
+
} else if (Array.isArray(data) && data.length === 1 && data[0].value != null && Object.keys(data[0]).length === 1) {
|
|
380
|
+
return data[0].value;
|
|
381
|
+
} else {
|
|
382
|
+
return data;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
|
|
373
387
|
_classPrivateFieldInitSpec(this, _insertObjects, {
|
|
374
388
|
writable: true,
|
|
375
389
|
value: function value(data) {
|
|
376
|
-
return (0, _modelHooksUtils.executeHook)("insert", _classPrivateFieldGet(_this, _insertHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
390
|
+
return (0, _modelHooksUtils.executeHook)("insert", _classPrivateFieldGet(_this, _insertHook), _classPrivateFieldGet(_this, _unWrap).call(_this, data), _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
377
391
|
}
|
|
378
392
|
});
|
|
379
393
|
|
|
380
394
|
_classPrivateFieldInitSpec(this, _updateObjects, {
|
|
381
395
|
writable: true,
|
|
382
396
|
value: function value(data) {
|
|
383
|
-
return (0, _modelHooksUtils.executeHook)("update", _classPrivateFieldGet(_this, _updateHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
397
|
+
return (0, _modelHooksUtils.executeHook)("update", _classPrivateFieldGet(_this, _updateHook), _classPrivateFieldGet(_this, _unWrap).call(_this, data), _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
384
398
|
}
|
|
385
399
|
});
|
|
386
400
|
|
|
387
401
|
_classPrivateFieldInitSpec(this, _deleteObjects, {
|
|
388
402
|
writable: true,
|
|
389
403
|
value: function value(data) {
|
|
390
|
-
return (0, _modelHooksUtils.executeHook)("delete", _classPrivateFieldGet(_this, _deleteHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
404
|
+
return (0, _modelHooksUtils.executeHook)("delete", _classPrivateFieldGet(_this, _deleteHook), _classPrivateFieldGet(_this, _unWrap).call(_this, data), _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
391
405
|
}
|
|
392
406
|
});
|
|
393
407
|
|
package/dist/ObserverStore.js
CHANGED
|
@@ -55,20 +55,28 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
55
55
|
|
|
56
56
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
57
57
|
|
|
58
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
59
|
+
|
|
58
60
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
59
61
|
|
|
60
62
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
61
63
|
|
|
62
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
63
|
-
|
|
64
64
|
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
65
65
|
|
|
66
|
+
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
67
|
+
|
|
68
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
69
|
+
|
|
66
70
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
67
71
|
|
|
68
72
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
69
73
|
|
|
70
74
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
71
75
|
|
|
76
|
+
var _queryPromises = /*#__PURE__*/new WeakMap();
|
|
77
|
+
|
|
78
|
+
var _unsubPromises = /*#__PURE__*/new WeakMap();
|
|
79
|
+
|
|
72
80
|
var _getUniqueSubs = /*#__PURE__*/new WeakMap();
|
|
73
81
|
|
|
74
82
|
var _propagateChange = /*#__PURE__*/new WeakMap();
|
|
@@ -91,8 +99,19 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
91
99
|
|
|
92
100
|
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _propagateInsertChange);
|
|
93
101
|
|
|
102
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _queryPromises, {
|
|
103
|
+
writable: true,
|
|
104
|
+
value: []
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _unsubPromises, {
|
|
108
|
+
writable: true,
|
|
109
|
+
value: []
|
|
110
|
+
});
|
|
111
|
+
|
|
94
112
|
_defineProperty(_assertThisInitialized(_this), "multipleSubscribe", function (subscriptions, callback) {
|
|
95
113
|
var dataPayload = {};
|
|
114
|
+
var subKey = (0, _uuid.v4)();
|
|
96
115
|
|
|
97
116
|
var areAllDone = function areAllDone() {
|
|
98
117
|
return subscriptions.map(function (_ref) {
|
|
@@ -105,7 +124,7 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
105
124
|
});
|
|
106
125
|
};
|
|
107
126
|
|
|
108
|
-
|
|
127
|
+
Promise.all(subscriptions.map(function (sub) {
|
|
109
128
|
var _sub = _slicedToArray(sub, 2),
|
|
110
129
|
name = _sub[0],
|
|
111
130
|
_sub$ = _sub[1],
|
|
@@ -118,62 +137,67 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
118
137
|
|
|
119
138
|
return _this.subscribe(name, wrappedCallback, filterFunction);
|
|
120
139
|
})).then(function (subKeys) {
|
|
121
|
-
var subKey = (0, _uuid.v4)();
|
|
122
140
|
_this._multipleSubscribed[subKey] = subKeys;
|
|
123
141
|
return subKey;
|
|
124
142
|
});
|
|
143
|
+
return subKey;
|
|
125
144
|
});
|
|
126
145
|
|
|
127
146
|
_defineProperty(_assertThisInitialized(_this), "subscribe", function (type, callback, filterFunction) {
|
|
128
|
-
var
|
|
147
|
+
var _this$_subscribed, _this$_subscribed$typ;
|
|
129
148
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
149
|
+
var subKey = (0, _uuid.v4)();
|
|
150
|
+
(_this$_subscribed$typ = (_this$_subscribed = _this._subscribed)[type]) !== null && _this$_subscribed$typ !== void 0 ? _this$_subscribed$typ : _this$_subscribed[type] = {};
|
|
133
151
|
|
|
134
|
-
_this.find(type, filterFunction).then(function (data) {
|
|
152
|
+
var prom = _this.find(type, filterFunction).then(function (data) {
|
|
135
153
|
_classPrivateFieldGet(_assertThisInitialized(_this), _subscribeToObjects).call(_assertThisInitialized(_this), type, data, {
|
|
136
154
|
callback: callback,
|
|
137
155
|
filterFunction: filterFunction,
|
|
138
156
|
subKey: subKey
|
|
139
157
|
});
|
|
140
158
|
|
|
141
|
-
|
|
159
|
+
callback(data);
|
|
142
160
|
});
|
|
143
161
|
|
|
162
|
+
_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).push(prom);
|
|
163
|
+
|
|
144
164
|
return subKey;
|
|
145
165
|
});
|
|
146
166
|
|
|
147
167
|
_defineProperty(_assertThisInitialized(_this), "unsubscribe", function (key) {
|
|
148
|
-
if (_this.
|
|
149
|
-
|
|
150
|
-
|
|
168
|
+
if (_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).length) {
|
|
169
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _unsubPromises, Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises)).then(function () {
|
|
170
|
+
if (_this._multipleSubscribed[key]) {
|
|
171
|
+
var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
|
|
172
|
+
_step;
|
|
151
173
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
_this.unsubscribe(sub);
|
|
157
|
-
}
|
|
158
|
-
} catch (err) {
|
|
159
|
-
_iterator.e(err);
|
|
160
|
-
} finally {
|
|
161
|
-
_iterator.f();
|
|
162
|
-
}
|
|
174
|
+
try {
|
|
175
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
176
|
+
var sub = _step.value;
|
|
163
177
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
178
|
+
_this.unsubscribe(sub);
|
|
179
|
+
}
|
|
180
|
+
} catch (err) {
|
|
181
|
+
_iterator.e(err);
|
|
182
|
+
} finally {
|
|
183
|
+
_iterator.f();
|
|
184
|
+
}
|
|
171
185
|
|
|
172
|
-
|
|
173
|
-
|
|
186
|
+
delete _this._multipleSubscribed[key];
|
|
187
|
+
} else {
|
|
188
|
+
for (var type in _this._subscribed) {
|
|
189
|
+
for (var id in _this._subscribed[type]) {
|
|
190
|
+
_this._subscribed[type][id] = _this._subscribed[type][id].filter(function (i) {
|
|
191
|
+
return i.subKey !== key;
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
if (_this._subscribed[type][id].length === 0) {
|
|
195
|
+
delete _this._subscribed[type][id];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
174
198
|
}
|
|
175
199
|
}
|
|
176
|
-
}
|
|
200
|
+
}));
|
|
177
201
|
}
|
|
178
202
|
});
|
|
179
203
|
|
|
@@ -197,8 +221,10 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
197
221
|
|
|
198
222
|
try {
|
|
199
223
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
224
|
+
var _sub$subKey, _out$_sub$subKey;
|
|
225
|
+
|
|
200
226
|
var sub = _step3.value;
|
|
201
|
-
out[sub.subKey]
|
|
227
|
+
(_out$_sub$subKey = out[_sub$subKey = sub.subKey]) !== null && _out$_sub$subKey !== void 0 ? _out$_sub$subKey : out[_sub$subKey] = sub;
|
|
202
228
|
}
|
|
203
229
|
} catch (err) {
|
|
204
230
|
_iterator3.e(err);
|
|
@@ -220,20 +246,21 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
220
246
|
writable: true,
|
|
221
247
|
value: function value() {
|
|
222
248
|
var objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
249
|
+
return (_classPrivateFieldGet(_assertThisInitialized(_this), _unsubPromises).length ? Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _unsubPromises)) : Promise.resolve()).then(function () {
|
|
250
|
+
if (objects.length) {
|
|
251
|
+
var type = objects[0].getModel().getType();
|
|
223
252
|
|
|
224
|
-
|
|
225
|
-
var type = objects[0].getModel().getType();
|
|
253
|
+
var uniqueSubs = _classPrivateFieldGet(_assertThisInitialized(_this), _getUniqueSubs).call(_assertThisInitialized(_this), objects, type);
|
|
226
254
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
});
|
|
234
|
-
}
|
|
255
|
+
(0, _batchPromises["default"])(10, uniqueSubs, function (_ref3) {
|
|
256
|
+
var callback = _ref3.callback,
|
|
257
|
+
filterFunction = _ref3.filterFunction;
|
|
258
|
+
return _this.find(type, filterFunction).then(callback);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
235
261
|
|
|
236
|
-
|
|
262
|
+
return objects;
|
|
263
|
+
});
|
|
237
264
|
}
|
|
238
265
|
});
|
|
239
266
|
|
|
@@ -245,12 +272,11 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
245
272
|
|
|
246
273
|
try {
|
|
247
274
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
275
|
+
var _this$_subscribed$typ2, _this$_subscribed$typ3;
|
|
276
|
+
|
|
248
277
|
var object = _step4.value;
|
|
249
278
|
var id = object.getId();
|
|
250
|
-
|
|
251
|
-
if (!_this._subscribed[type][id]) {
|
|
252
|
-
_this._subscribed[type][id] = [];
|
|
253
|
-
}
|
|
279
|
+
(_this$_subscribed$typ3 = (_this$_subscribed$typ2 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ3 !== void 0 ? _this$_subscribed$typ3 : _this$_subscribed$typ2[id] = [];
|
|
254
280
|
|
|
255
281
|
_this._subscribed[type][id].push(item);
|
|
256
282
|
}
|
|
@@ -297,71 +323,73 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
297
323
|
function _propagateInsertChange2(type, newObjects) {
|
|
298
324
|
var _this3 = this;
|
|
299
325
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
326
|
+
return (_classPrivateFieldGet(this, _unsubPromises).length ? Promise.all(_classPrivateFieldGet(this, _unsubPromises)) : Promise.resolve()).then(function () {
|
|
327
|
+
if (_this3._subscribed[type]) {
|
|
328
|
+
var uniqueSubs = {};
|
|
329
|
+
var objects = Object.values(_this3._subscribed[type]);
|
|
303
330
|
|
|
304
|
-
|
|
305
|
-
|
|
331
|
+
for (var _i2 = 0, _objects = objects; _i2 < _objects.length; _i2++) {
|
|
332
|
+
var object = _objects[_i2];
|
|
306
333
|
|
|
307
|
-
|
|
308
|
-
|
|
334
|
+
var _iterator5 = _createForOfIteratorHelper(object),
|
|
335
|
+
_step5;
|
|
309
336
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
337
|
+
try {
|
|
338
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
339
|
+
var sub = _step5.value;
|
|
313
340
|
|
|
314
|
-
|
|
315
|
-
|
|
341
|
+
if (!uniqueSubs[sub.subKey]) {
|
|
342
|
+
uniqueSubs[sub.subKey] = sub;
|
|
343
|
+
}
|
|
316
344
|
}
|
|
345
|
+
} catch (err) {
|
|
346
|
+
_iterator5.e(err);
|
|
347
|
+
} finally {
|
|
348
|
+
_iterator5.f();
|
|
317
349
|
}
|
|
318
|
-
} catch (err) {
|
|
319
|
-
_iterator5.e(err);
|
|
320
|
-
} finally {
|
|
321
|
-
_iterator5.f();
|
|
322
350
|
}
|
|
323
|
-
}
|
|
324
351
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
352
|
+
var possibleSubs = Object.values(uniqueSubs);
|
|
353
|
+
(0, _batchPromises["default"])(10, possibleSubs, function (_ref4) {
|
|
354
|
+
var callback = _ref4.callback,
|
|
355
|
+
filterFunction = _ref4.filterFunction;
|
|
356
|
+
var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
|
|
330
357
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
358
|
+
if (objectsToSubscribe.length) {
|
|
359
|
+
// Check if the new objects matter
|
|
360
|
+
return _this3.find(type, filterFunction).then(function (data) {
|
|
361
|
+
var subKey;
|
|
335
362
|
|
|
336
|
-
|
|
337
|
-
|
|
363
|
+
var _iterator6 = _createForOfIteratorHelper(data),
|
|
364
|
+
_step6;
|
|
338
365
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
366
|
+
try {
|
|
367
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
368
|
+
var d = _step6.value;
|
|
342
369
|
|
|
343
|
-
|
|
370
|
+
var item = _this3._subscribed[d.getModel().getType()][d.getId()];
|
|
344
371
|
|
|
345
|
-
|
|
346
|
-
|
|
372
|
+
subKey = item ? item.subKey : null;
|
|
373
|
+
if (subKey) break;
|
|
374
|
+
}
|
|
375
|
+
} catch (err) {
|
|
376
|
+
_iterator6.e(err);
|
|
377
|
+
} finally {
|
|
378
|
+
_iterator6.f();
|
|
347
379
|
}
|
|
348
|
-
} catch (err) {
|
|
349
|
-
_iterator6.e(err);
|
|
350
|
-
} finally {
|
|
351
|
-
_iterator6.f();
|
|
352
|
-
}
|
|
353
380
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
381
|
+
_classPrivateFieldGet(_this3, _subscribeToObjects).call(_this3, type, objectsToSubscribe, {
|
|
382
|
+
callback: callback,
|
|
383
|
+
filterFunction: filterFunction,
|
|
384
|
+
subKey: subKey
|
|
385
|
+
});
|
|
359
386
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
387
|
+
return data;
|
|
388
|
+
}).then(callback);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
});
|
|
365
393
|
}
|
|
366
394
|
|
|
367
395
|
var _default = ObserverStore;
|