dataflux 1.7.1 → 1.7.5
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 +24 -5
- package/dist/BasicObj.js +3 -1
- package/dist/Model.js +48 -14
- package/dist/ObserverStore.js +124 -97
- package/dist/dataflux.min.js +2 -0
- package/dist/dataflux.min.js.map +1 -0
- 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:
|
package/dist/BasicObj.js
CHANGED
|
@@ -48,7 +48,9 @@ function setValues(values, model, SubObj, parent, context) {
|
|
|
48
48
|
context[key] = mmnt.isValid() ? mmnt : value;
|
|
49
49
|
} else if (model.options.deep && value != null && _typeof(value) === "object" && !Array.isArray(value)) {
|
|
50
50
|
context[key] = new SubObj(parent, key, value, model);
|
|
51
|
-
} else if (model.options.deep && value != null && Array.isArray(value)) {
|
|
51
|
+
} else if (model.options.deep && value != null && Array.isArray(value) && !value.some(function (str) {
|
|
52
|
+
return ["string", "number"].includes(_typeof(str));
|
|
53
|
+
})) {
|
|
52
54
|
context[key] = value.map(function (i) {
|
|
53
55
|
return new SubObj(parent, key, i, model);
|
|
54
56
|
});
|
package/dist/Model.js
CHANGED
|
@@ -17,8 +17,6 @@ var _SubObj = _interopRequireDefault(require("./SubObj"));
|
|
|
17
17
|
|
|
18
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
19
|
|
|
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
20
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
23
21
|
|
|
24
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."); }
|
|
@@ -31,6 +29,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
31
29
|
|
|
32
30
|
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; }
|
|
33
31
|
|
|
32
|
+
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); }
|
|
33
|
+
|
|
34
34
|
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; } } }; }
|
|
35
35
|
|
|
36
36
|
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); }
|
|
@@ -99,6 +99,8 @@ var _bulkOperation = /*#__PURE__*/new WeakMap();
|
|
|
99
99
|
|
|
100
100
|
var _toArray = /*#__PURE__*/new WeakMap();
|
|
101
101
|
|
|
102
|
+
var _unWrap = /*#__PURE__*/new WeakMap();
|
|
103
|
+
|
|
102
104
|
var _insertObjects = /*#__PURE__*/new WeakMap();
|
|
103
105
|
|
|
104
106
|
var _updateObjects = /*#__PURE__*/new WeakMap();
|
|
@@ -193,7 +195,8 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
193
195
|
return _this.getStore().whenSaved(_this.getType())["catch"](function (e) {
|
|
194
196
|
throw new Error("You cannot perform load() on an unsaved object.");
|
|
195
197
|
}).then(function () {
|
|
196
|
-
var res = _classPrivateFieldGet(_this, _loadFunction).call(_this, obj.toJSON());
|
|
198
|
+
var res = _classPrivateFieldGet(_this, _loadFunction).call(_this, obj.toJSON()); // toJSON to avoid side effects;
|
|
199
|
+
|
|
197
200
|
|
|
198
201
|
if (typeof res === "string") {
|
|
199
202
|
return _classPrivateFieldGet(_this, _axios).call(_this, {
|
|
@@ -260,13 +263,11 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
260
263
|
|
|
261
264
|
_defineProperty(this, "retrieveAll", function () {
|
|
262
265
|
return (0, _modelHooksUtils.executeHook)("retrieve", _classPrivateFieldGet(_this, _retrieveHook), null, _classPrivateFieldGet(_this, _axios)).then(function (data) {
|
|
263
|
-
if (Array.isArray(data)) {
|
|
264
|
-
return data;
|
|
265
|
-
} else {
|
|
266
|
+
if (!Array.isArray(data)) {
|
|
266
267
|
_classPrivateFieldSet(_this, _singleItemQuery, true);
|
|
267
|
-
|
|
268
|
-
return [data];
|
|
269
268
|
}
|
|
269
|
+
|
|
270
|
+
return _classPrivateFieldGet(_this, _toArray).call(_this, data);
|
|
270
271
|
});
|
|
271
272
|
});
|
|
272
273
|
|
|
@@ -286,7 +287,13 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
286
287
|
if (!_this.options.lazyLoad) {
|
|
287
288
|
return Promise.reject("Factory can be used only on a model declared with lazyLoad: true");
|
|
288
289
|
} else {
|
|
289
|
-
return (0, _modelHooksUtils.executeHook)("retrieve", _classPrivateFieldGet(_this, _retrieveHook), params, _classPrivateFieldGet(_this, _axios))
|
|
290
|
+
return (0, _modelHooksUtils.executeHook)("retrieve", _classPrivateFieldGet(_this, _retrieveHook), params, _classPrivateFieldGet(_this, _axios)).then(function (data) {
|
|
291
|
+
if (!Array.isArray(data)) {
|
|
292
|
+
_classPrivateFieldSet(_this, _singleItemQuery, true);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return _classPrivateFieldGet(_this, _toArray).call(_this, data);
|
|
296
|
+
});
|
|
290
297
|
}
|
|
291
298
|
});
|
|
292
299
|
|
|
@@ -351,9 +358,36 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
351
358
|
writable: true,
|
|
352
359
|
value: function value(data) {
|
|
353
360
|
if (Array.isArray(data)) {
|
|
354
|
-
|
|
361
|
+
if (data.every(function (str) {
|
|
362
|
+
return ["string", "number"].includes(_typeof(str));
|
|
363
|
+
})) {
|
|
364
|
+
return [{
|
|
365
|
+
value: data
|
|
366
|
+
}];
|
|
367
|
+
} else {
|
|
368
|
+
return data;
|
|
369
|
+
}
|
|
355
370
|
} else {
|
|
356
|
-
|
|
371
|
+
if (["string", "number"].includes(_typeof(data))) {
|
|
372
|
+
return [{
|
|
373
|
+
value: data
|
|
374
|
+
}];
|
|
375
|
+
} else {
|
|
376
|
+
return [data];
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
_classPrivateFieldInitSpec(this, _unWrap, {
|
|
383
|
+
writable: true,
|
|
384
|
+
value: function value(data) {
|
|
385
|
+
if (data.value != null && Object.keys(data).length === 1) {
|
|
386
|
+
return data.value;
|
|
387
|
+
} else if (Array.isArray(data) && data.length === 1 && data[0].value != null && Object.keys(data[0]).length === 1) {
|
|
388
|
+
return data[0].value;
|
|
389
|
+
} else {
|
|
390
|
+
return data;
|
|
357
391
|
}
|
|
358
392
|
}
|
|
359
393
|
});
|
|
@@ -361,21 +395,21 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
361
395
|
_classPrivateFieldInitSpec(this, _insertObjects, {
|
|
362
396
|
writable: true,
|
|
363
397
|
value: function value(data) {
|
|
364
|
-
return (0, _modelHooksUtils.executeHook)("insert", _classPrivateFieldGet(_this, _insertHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
398
|
+
return (0, _modelHooksUtils.executeHook)("insert", _classPrivateFieldGet(_this, _insertHook), _classPrivateFieldGet(_this, _unWrap).call(_this, data), _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
365
399
|
}
|
|
366
400
|
});
|
|
367
401
|
|
|
368
402
|
_classPrivateFieldInitSpec(this, _updateObjects, {
|
|
369
403
|
writable: true,
|
|
370
404
|
value: function value(data) {
|
|
371
|
-
return (0, _modelHooksUtils.executeHook)("update", _classPrivateFieldGet(_this, _updateHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
405
|
+
return (0, _modelHooksUtils.executeHook)("update", _classPrivateFieldGet(_this, _updateHook), _classPrivateFieldGet(_this, _unWrap).call(_this, data), _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
372
406
|
}
|
|
373
407
|
});
|
|
374
408
|
|
|
375
409
|
_classPrivateFieldInitSpec(this, _deleteObjects, {
|
|
376
410
|
writable: true,
|
|
377
411
|
value: function value(data) {
|
|
378
|
-
return (0, _modelHooksUtils.executeHook)("delete", _classPrivateFieldGet(_this, _deleteHook), data, _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
412
|
+
return (0, _modelHooksUtils.executeHook)("delete", _classPrivateFieldGet(_this, _deleteHook), _classPrivateFieldGet(_this, _unWrap).call(_this, data), _classPrivateFieldGet(_this, _axios)).then(_classPrivateFieldGet(_this, _toArray));
|
|
379
413
|
}
|
|
380
414
|
});
|
|
381
415
|
|
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,6 +99,16 @@ 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 = {};
|
|
96
114
|
|
|
@@ -125,55 +143,60 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
125
143
|
});
|
|
126
144
|
|
|
127
145
|
_defineProperty(_assertThisInitialized(_this), "subscribe", function (type, callback, filterFunction) {
|
|
128
|
-
var
|
|
146
|
+
var _this$_subscribed, _this$_subscribed$typ;
|
|
129
147
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
148
|
+
var subKey = (0, _uuid.v4)();
|
|
149
|
+
(_this$_subscribed$typ = (_this$_subscribed = _this._subscribed)[type]) !== null && _this$_subscribed$typ !== void 0 ? _this$_subscribed$typ : _this$_subscribed[type] = {};
|
|
133
150
|
|
|
134
|
-
_this.find(type, filterFunction).then(function (data) {
|
|
151
|
+
var prom = _this.find(type, filterFunction).then(function (data) {
|
|
135
152
|
_classPrivateFieldGet(_assertThisInitialized(_this), _subscribeToObjects).call(_assertThisInitialized(_this), type, data, {
|
|
136
153
|
callback: callback,
|
|
137
154
|
filterFunction: filterFunction,
|
|
138
155
|
subKey: subKey
|
|
139
156
|
});
|
|
140
157
|
|
|
141
|
-
|
|
158
|
+
callback(data);
|
|
142
159
|
});
|
|
143
160
|
|
|
161
|
+
_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).push(prom);
|
|
162
|
+
|
|
144
163
|
return subKey;
|
|
145
164
|
});
|
|
146
165
|
|
|
147
166
|
_defineProperty(_assertThisInitialized(_this), "unsubscribe", function (key) {
|
|
148
|
-
if (_this.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
154
|
-
var sub = _step.value;
|
|
167
|
+
if (_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).length) {
|
|
168
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _unsubPromises, Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises)).then(function () {
|
|
169
|
+
if (_this._multipleSubscribed[key]) {
|
|
170
|
+
var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
|
|
171
|
+
_step;
|
|
155
172
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
_iterator.e(err);
|
|
160
|
-
} finally {
|
|
161
|
-
_iterator.f();
|
|
162
|
-
}
|
|
173
|
+
try {
|
|
174
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
175
|
+
var sub = _step.value;
|
|
163
176
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
177
|
+
_this.unsubscribe(sub);
|
|
178
|
+
}
|
|
179
|
+
} catch (err) {
|
|
180
|
+
_iterator.e(err);
|
|
181
|
+
} finally {
|
|
182
|
+
_iterator.f();
|
|
183
|
+
}
|
|
171
184
|
|
|
172
|
-
|
|
173
|
-
|
|
185
|
+
delete _this._multipleSubscribed[key];
|
|
186
|
+
} else {
|
|
187
|
+
for (var type in _this._subscribed) {
|
|
188
|
+
for (var id in _this._subscribed[type]) {
|
|
189
|
+
_this._subscribed[type][id] = _this._subscribed[type][id].filter(function (i) {
|
|
190
|
+
return i.subKey !== key;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
if (_this._subscribed[type][id].length === 0) {
|
|
194
|
+
delete _this._subscribed[type][id];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
174
197
|
}
|
|
175
198
|
}
|
|
176
|
-
}
|
|
199
|
+
}));
|
|
177
200
|
}
|
|
178
201
|
});
|
|
179
202
|
|
|
@@ -197,8 +220,10 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
197
220
|
|
|
198
221
|
try {
|
|
199
222
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
223
|
+
var _sub$subKey, _out$_sub$subKey;
|
|
224
|
+
|
|
200
225
|
var sub = _step3.value;
|
|
201
|
-
out[sub.subKey]
|
|
226
|
+
(_out$_sub$subKey = out[_sub$subKey = sub.subKey]) !== null && _out$_sub$subKey !== void 0 ? _out$_sub$subKey : out[_sub$subKey] = sub;
|
|
202
227
|
}
|
|
203
228
|
} catch (err) {
|
|
204
229
|
_iterator3.e(err);
|
|
@@ -220,20 +245,21 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
220
245
|
writable: true,
|
|
221
246
|
value: function value() {
|
|
222
247
|
var objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
248
|
+
return (_classPrivateFieldGet(_assertThisInitialized(_this), _unsubPromises).length ? Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _unsubPromises)) : Promise.resolve()).then(function () {
|
|
249
|
+
if (objects.length) {
|
|
250
|
+
var type = objects[0].getModel().getType();
|
|
223
251
|
|
|
224
|
-
|
|
225
|
-
var type = objects[0].getModel().getType();
|
|
226
|
-
|
|
227
|
-
var uniqueSubs = _classPrivateFieldGet(_assertThisInitialized(_this), _getUniqueSubs).call(_assertThisInitialized(_this), objects, type);
|
|
252
|
+
var uniqueSubs = _classPrivateFieldGet(_assertThisInitialized(_this), _getUniqueSubs).call(_assertThisInitialized(_this), objects, type);
|
|
228
253
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
254
|
+
(0, _batchPromises["default"])(10, uniqueSubs, function (_ref3) {
|
|
255
|
+
var callback = _ref3.callback,
|
|
256
|
+
filterFunction = _ref3.filterFunction;
|
|
257
|
+
return _this.find(type, filterFunction).then(callback);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
235
260
|
|
|
236
|
-
|
|
261
|
+
return objects;
|
|
262
|
+
});
|
|
237
263
|
}
|
|
238
264
|
});
|
|
239
265
|
|
|
@@ -245,12 +271,11 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
245
271
|
|
|
246
272
|
try {
|
|
247
273
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
274
|
+
var _this$_subscribed$typ2, _this$_subscribed$typ3;
|
|
275
|
+
|
|
248
276
|
var object = _step4.value;
|
|
249
277
|
var id = object.getId();
|
|
250
|
-
|
|
251
|
-
if (!_this._subscribed[type][id]) {
|
|
252
|
-
_this._subscribed[type][id] = [];
|
|
253
|
-
}
|
|
278
|
+
(_this$_subscribed$typ3 = (_this$_subscribed$typ2 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ3 !== void 0 ? _this$_subscribed$typ3 : _this$_subscribed$typ2[id] = [];
|
|
254
279
|
|
|
255
280
|
_this._subscribed[type][id].push(item);
|
|
256
281
|
}
|
|
@@ -297,71 +322,73 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
297
322
|
function _propagateInsertChange2(type, newObjects) {
|
|
298
323
|
var _this3 = this;
|
|
299
324
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
325
|
+
return (_classPrivateFieldGet(this, _unsubPromises).length ? Promise.all(_classPrivateFieldGet(this, _unsubPromises)) : Promise.resolve()).then(function () {
|
|
326
|
+
if (_this3._subscribed[type]) {
|
|
327
|
+
var uniqueSubs = {};
|
|
328
|
+
var objects = Object.values(_this3._subscribed[type]);
|
|
303
329
|
|
|
304
|
-
|
|
305
|
-
|
|
330
|
+
for (var _i2 = 0, _objects = objects; _i2 < _objects.length; _i2++) {
|
|
331
|
+
var object = _objects[_i2];
|
|
306
332
|
|
|
307
|
-
|
|
308
|
-
|
|
333
|
+
var _iterator5 = _createForOfIteratorHelper(object),
|
|
334
|
+
_step5;
|
|
309
335
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
336
|
+
try {
|
|
337
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
338
|
+
var sub = _step5.value;
|
|
313
339
|
|
|
314
|
-
|
|
315
|
-
|
|
340
|
+
if (!uniqueSubs[sub.subKey]) {
|
|
341
|
+
uniqueSubs[sub.subKey] = sub;
|
|
342
|
+
}
|
|
316
343
|
}
|
|
344
|
+
} catch (err) {
|
|
345
|
+
_iterator5.e(err);
|
|
346
|
+
} finally {
|
|
347
|
+
_iterator5.f();
|
|
317
348
|
}
|
|
318
|
-
} catch (err) {
|
|
319
|
-
_iterator5.e(err);
|
|
320
|
-
} finally {
|
|
321
|
-
_iterator5.f();
|
|
322
349
|
}
|
|
323
|
-
}
|
|
324
350
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
351
|
+
var possibleSubs = Object.values(uniqueSubs);
|
|
352
|
+
(0, _batchPromises["default"])(10, possibleSubs, function (_ref4) {
|
|
353
|
+
var callback = _ref4.callback,
|
|
354
|
+
filterFunction = _ref4.filterFunction;
|
|
355
|
+
var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
|
|
330
356
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
357
|
+
if (objectsToSubscribe.length) {
|
|
358
|
+
// Check if the new objects matter
|
|
359
|
+
return _this3.find(type, filterFunction).then(function (data) {
|
|
360
|
+
var subKey;
|
|
335
361
|
|
|
336
|
-
|
|
337
|
-
|
|
362
|
+
var _iterator6 = _createForOfIteratorHelper(data),
|
|
363
|
+
_step6;
|
|
338
364
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
365
|
+
try {
|
|
366
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
367
|
+
var d = _step6.value;
|
|
342
368
|
|
|
343
|
-
|
|
369
|
+
var item = _this3._subscribed[d.getModel().getType()][d.getId()];
|
|
344
370
|
|
|
345
|
-
|
|
346
|
-
|
|
371
|
+
subKey = item ? item.subKey : null;
|
|
372
|
+
if (subKey) break;
|
|
373
|
+
}
|
|
374
|
+
} catch (err) {
|
|
375
|
+
_iterator6.e(err);
|
|
376
|
+
} finally {
|
|
377
|
+
_iterator6.f();
|
|
347
378
|
}
|
|
348
|
-
} catch (err) {
|
|
349
|
-
_iterator6.e(err);
|
|
350
|
-
} finally {
|
|
351
|
-
_iterator6.f();
|
|
352
|
-
}
|
|
353
379
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
380
|
+
_classPrivateFieldGet(_this3, _subscribeToObjects).call(_this3, type, objectsToSubscribe, {
|
|
381
|
+
callback: callback,
|
|
382
|
+
filterFunction: filterFunction,
|
|
383
|
+
subKey: subKey
|
|
384
|
+
});
|
|
359
385
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
386
|
+
return data;
|
|
387
|
+
}).then(callback);
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
});
|
|
365
392
|
}
|
|
366
393
|
|
|
367
394
|
var _default = ObserverStore;
|