dataflux 1.15.2 → 1.17.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 +87 -20
- package/dist/BasicObj.js +6 -0
- package/dist/Model.js +6 -3
- package/dist/ReactStore.js +16 -3
- package/dist/Store.js +60 -26
- package/dist/dataflux.min.js +1 -1
- package/dist/dataflux.min.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -254,6 +254,70 @@ function MyComponent() {
|
|
|
254
254
|
}
|
|
255
255
|
```
|
|
256
256
|
|
|
257
|
+
### Example 7 - React props and observability
|
|
258
|
+
|
|
259
|
+
If you pass an object as a prop to a React component, the component will not refresh if the object changes.
|
|
260
|
+
|
|
261
|
+
```jsx
|
|
262
|
+
class MyComponent extends React.Component {
|
|
263
|
+
constructor(props) {
|
|
264
|
+
super(props);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
componentDidMount() {
|
|
268
|
+
store.findAll("book", "books", this, ({price}) => price < 20);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
render(){
|
|
272
|
+
const {books} = this.state;
|
|
273
|
+
|
|
274
|
+
return books.map(book =>
|
|
275
|
+
<BookView
|
|
276
|
+
// key={book.getFingerprint()}
|
|
277
|
+
book={book}
|
|
278
|
+
/>);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
class BookView extends React.Component {
|
|
283
|
+
constructor(props) {
|
|
284
|
+
super(props);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
render(){
|
|
288
|
+
const {book} = this.props;
|
|
289
|
+
|
|
290
|
+
return <div>book.price</div>;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
```
|
|
297
|
+
If you now do `books[0].set("price", 18)`, the BookView object will not update the price. You could address this by adding a `key={book.getFingerprint()}` prop. However, this approach forces the mounting of the component at every object change.
|
|
298
|
+
|
|
299
|
+
A better approach is to use the method `didUpdate()` inside `componentDidUpdate` to check if any of the objects in the props changed.
|
|
300
|
+
|
|
301
|
+
```jsx
|
|
302
|
+
class BookView extends React.Component {
|
|
303
|
+
constructor(props) {
|
|
304
|
+
super(props);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
componentDidUpdate() {
|
|
308
|
+
store.didUpdate(this);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
render(){
|
|
312
|
+
const {book} = this.props;
|
|
313
|
+
|
|
314
|
+
return <div>book.price</div>;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Without further changes to the code, the new `book.price` will be rendered when the book object in the props is edited.
|
|
320
|
+
|
|
257
321
|
|
|
258
322
|
## Configuration
|
|
259
323
|
|
|
@@ -286,25 +350,25 @@ const book = new Model("book", options);
|
|
|
286
350
|
|
|
287
351
|
All the possible options for a model creation are (they are all optional):
|
|
288
352
|
|
|
289
|
-
| Name
|
|
290
|
-
|
|
291
|
-
| retrieve
|
|
292
|
-
| insert
|
|
293
|
-
| update
|
|
294
|
-
| delete
|
|
295
|
-
| fields
|
|
296
|
-
| headers
|
|
297
|
-
| load
|
|
298
|
-
| axios
|
|
299
|
-
| parseMoment
|
|
300
|
-
| hiddenFields
|
|
301
|
-
| deep
|
|
302
|
-
| lazyLoad
|
|
303
|
-
| validate
|
|
304
|
-
| autoRefresh
|
|
305
|
-
| autoSave
|
|
306
|
-
| pre
|
|
307
|
-
| post
|
|
353
|
+
| Name | Description | Default |
|
|
354
|
+
|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
|
|
355
|
+
| retrieve | Describes the operation to retrieve the collection of objects from the REST API. It can be an operation object or a function. See [operations](#operations). | `{method: "get"}` |
|
|
356
|
+
| insert | Describes the operation to insert a new object in the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "post"}` |
|
|
357
|
+
| update | Describes the operation to update objects of the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "put"}` |
|
|
358
|
+
| delete | Describes the operation to remove objects from the collection. It can be an operation object or a function. See [operations](#operations). | `{method: "delete"}` |
|
|
359
|
+
| fields | An array of strings defining which attributes the retrieved objects should have. Essentially, it allows you to contemporarily specify the [X-Fields header](https://flask-restplus.readthedocs.io/en/stable/mask.html) and the [fields GET parameter](https://developers.google.com/slides/api/guides/performance#partial). This reduces transfer size and memory usage. E.g., if you have a collection of books, of which you are interested only in the name, you can define `fields: ["name"]`. In combination with `load` it allows for partial lazy load of the objects. | All the fields |
|
|
360
|
+
| headers | A dictionary of headers for the HTTP request. E.g., `{"Authorization": "bearer XXXX"}`. | No headers |
|
|
361
|
+
| load | A function that allows to enrich the objects on demand. E.g., you can use `fields` to download only the titles of a collection of books, and `load` to load completely the object. See [object enrichment](#object-enrichment). |
|
|
362
|
+
| axios | It allows to specify an axios instance to be used for the queries. If not specified, a new one will be used. | A new axios instance |
|
|
363
|
+
| parseMoment | Automatically creates Moment.js objects out of ISO8601 strings. E.g., if an object has a property `createdAt: "2022-01-07T21:38:50.295Z"`, this will be transformed to a moment object. | |
|
|
364
|
+
| hiddenFields | An array of attribute names that will never be sent back to the API. E.g., if you set `hiddenFields: ["pages"]`, a book object can contain an attribute `pages` locally, but this will be stripped out in PUT/POST requests. |
|
|
365
|
+
| deep | A boolean defining if nested objects should be enriched with the object methods. | true |
|
|
366
|
+
| lazyLoad | A boolean defining if the model should be lazy loaded on the first use. This takes precedence over the lazyLoad declared during store initialization. | false |
|
|
367
|
+
| validate | A dictionary containing functions to validate the objects of this model. See [objects validation](#objects-validation) | no validation |
|
|
368
|
+
| autoRefresh | Set auto refresh for the specific model. See `autoRefresh` in the [store config](#configuration). | |
|
|
369
|
+
| autoSave | It allows to specify `autoSave` at model level. If store.autoSave is true, `autoSave: false` at model level will allow to disable autoSave only for the specific model. |
|
|
370
|
+
| pre(object, objects) | A function that is executed for every object retrieved, before creating the collection in the store. It is useful for pre-processing every data item received from the API. It receives in input a object of the collection (first parameter) and the entire collection (second parameter). |
|
|
371
|
+
| post | A function that is executed for every object retrieved before delete, update, and insert operations. It is useful for post-processing every data item before sending them back to the API. It receives in input a object of the collection (first parameter) and the entire collection (second parameter). |
|
|
308
372
|
|
|
309
373
|
### Operations
|
|
310
374
|
As described in the table above, there are four possible operations: **retrieve, insert, update,** and **delete**. An operation can be defined as an operation object or a function.
|
|
@@ -576,6 +640,8 @@ The store has the following method.
|
|
|
576
640
|
| reset(type) | This method syncs all the objects in the store with the remote version offered by the REST APIs (`remote -> local`). Remote changes are applied locally, including adding/removing objects. Objects edited locally but not yet persisted are reverted to the corresponding remote object. If a model type is passed, only objects of that type will be reset. |
|
|
577
641
|
| findSync(type, filterFunction) | This method returns the objects in a synchronous way (no Promise). However, *it works only if you already performed an async operation (e.g., like refresh, load, find, subscribe) or if you set lazyLoad to false and the store had enough time to load.* |
|
|
578
642
|
| hasChanged(type, object) | This method receives in input a model type and an object (optional). It returns a boolean, `true` if the object is dirty (it changed but it has not yet being persisted). If the object is not passed, the method checks if any of the objects of the specified model type has changed. |
|
|
643
|
+
| didUpdate(context) | If you pass an object as a prop to a React component, the component will not refresh if the object changes. To address this, you can use this method inside the `componentDidUpdate` to check if any of the objects changed. See [example 6](#example-7---react-props-and-observability) |
|
|
644
|
+
| getCollection(type) | This method receives in input a model type . It returns all the raw (JSON) objects available for that model. |
|
|
579
645
|
|
|
580
646
|
### Insert vs. Mock
|
|
581
647
|
|
|
@@ -631,6 +697,7 @@ Each object created is enriched with the following methods.
|
|
|
631
697
|
| getError() | If an operation on an object triggers an error, this error can be retrieved with `getError()`. This allows to observe specific objects' errors, instead of the generic `store.on("error", ...)`. |
|
|
632
698
|
| getError(attributeName) | This method allows you to check if the specificed attribute generated any error according to the validation property specified in the model. See [objects validation](#objects-validation). |
|
|
633
699
|
| setError(error) | Additionally to DataFlux's errors, you can trigger your own errors with this method. Other components observing this objet's error will be notified. |
|
|
700
|
+
| isDataflux() | This method returns true for all dataflux objects. |
|
|
634
701
|
|
|
635
702
|
### Deep Objects
|
|
636
703
|
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.
|
|
@@ -718,7 +785,7 @@ class MyComponent extends React.Component {
|
|
|
718
785
|
return <TextField
|
|
719
786
|
value={book.title}
|
|
720
787
|
onChange={store.handleChange(book, "title")}
|
|
721
|
-
error={object.getError("title")}
|
|
788
|
+
error={object.getError("title")}
|
|
722
789
|
// E.g., in material UI the test field will be red in case of errors
|
|
723
790
|
/>;
|
|
724
791
|
}
|
package/dist/BasicObj.js
CHANGED
|
@@ -78,6 +78,12 @@ var BasicObj = exports.BasicObj = /*#__PURE__*/function () {
|
|
|
78
78
|
_classPrivateFieldInitSpec(this, _id, null);
|
|
79
79
|
_classPrivateFieldInitSpec(this, _error, {});
|
|
80
80
|
_classPrivateFieldInitSpec(this, _model, void 0);
|
|
81
|
+
_defineProperty(this, "isDataflux", function () {
|
|
82
|
+
return true;
|
|
83
|
+
});
|
|
84
|
+
_defineProperty(this, "isMock", function () {
|
|
85
|
+
return false;
|
|
86
|
+
});
|
|
81
87
|
_defineProperty(this, "setId", function (id) {
|
|
82
88
|
_this.id = id;
|
|
83
89
|
});
|
package/dist/Model.js
CHANGED
|
@@ -225,7 +225,9 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
|
|
|
225
225
|
return _classPrivateFieldGet(_toArray, _this).call(_this, data);
|
|
226
226
|
}).then(function (data) {
|
|
227
227
|
var _this$options;
|
|
228
|
-
return (_this$options = _this.options) !== null && _this$options !== void 0 && _this$options.pre ? data.map(
|
|
228
|
+
return (_this$options = _this.options) !== null && _this$options !== void 0 && _this$options.pre ? data.map(function (n) {
|
|
229
|
+
return _this.options.pre(n, data);
|
|
230
|
+
}) : data;
|
|
229
231
|
});
|
|
230
232
|
});
|
|
231
233
|
_defineProperty(this, "insertObjects", function (objects) {
|
|
@@ -297,11 +299,12 @@ var Model = exports["default"] = /*#__PURE__*/_createClass(function Model(name)
|
|
|
297
299
|
}
|
|
298
300
|
});
|
|
299
301
|
_classPrivateFieldInitSpec(this, _unWrap, function (objects) {
|
|
300
|
-
var
|
|
302
|
+
var arrayObjects = Object.values(objects);
|
|
303
|
+
var data = arrayObjects.map(function (object) {
|
|
301
304
|
return _classPrivateFieldGet(_removeHiddenFields, _this).call(_this, object.toJSON());
|
|
302
305
|
}).map(function (object) {
|
|
303
306
|
var _this$options2;
|
|
304
|
-
return (_this$options2 = _this.options) !== null && _this$options2 !== void 0 && _this$options2.post ? _this.options.post(object) : object;
|
|
307
|
+
return (_this$options2 = _this.options) !== null && _this$options2 !== void 0 && _this$options2.post ? _this.options.post(object, arrayObjects) : object;
|
|
305
308
|
});
|
|
306
309
|
if (data.value != null && Object.keys(data).length === 1) {
|
|
307
310
|
return data.value;
|
package/dist/ReactStore.js
CHANGED
|
@@ -22,12 +22,12 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
22
22
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
23
23
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
24
24
|
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
25
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
26
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
27
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
28
25
|
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
29
26
|
function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
|
|
30
27
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
28
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
29
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
30
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
31
31
|
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
32
32
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } /*
|
|
33
33
|
* MIT License
|
|
@@ -60,6 +60,19 @@ var ReactStore = exports["default"] = /*#__PURE__*/function (_ObserverStore) {
|
|
|
60
60
|
_classCallCheck(this, ReactStore);
|
|
61
61
|
_this = _callSuper(this, ReactStore, [options]);
|
|
62
62
|
_classPrivateMethodInitSpec(_this, _ReactStore_brand);
|
|
63
|
+
_defineProperty(_this, "didUpdate", function (context) {
|
|
64
|
+
var _context$props;
|
|
65
|
+
var objects = Object.values((_context$props = context === null || context === void 0 ? void 0 : context.props) !== null && _context$props !== void 0 ? _context$props : {}).filter(function (i) {
|
|
66
|
+
return i.isDataflux();
|
|
67
|
+
});
|
|
68
|
+
var _f = objects.map(function (i) {
|
|
69
|
+
return i.getFingerprint();
|
|
70
|
+
}).join(".");
|
|
71
|
+
if (_f !== context.___obs_f) {
|
|
72
|
+
context.forceUpdate();
|
|
73
|
+
}
|
|
74
|
+
context.___obs_f = _f;
|
|
75
|
+
});
|
|
63
76
|
_classPrivateFieldInitSpec(_this, _addSubscriptionToContext, function (context, subKey) {
|
|
64
77
|
// I know...
|
|
65
78
|
context.___obs_subkeys = context.___obs_subkeys || [];
|
package/dist/Store.js
CHANGED
|
@@ -74,6 +74,32 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
74
74
|
});
|
|
75
75
|
return filterFunction ? all.filter(filterFunction) : all;
|
|
76
76
|
});
|
|
77
|
+
_defineProperty(this, "_validateTypeInput", function (type) {
|
|
78
|
+
if (!_this.models[type]) {
|
|
79
|
+
throw new Error("Not valid model type");
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
_defineProperty(this, "_getDiffSync", function (type) {
|
|
83
|
+
var objects = Object.values(_this.models[type].storedObjects);
|
|
84
|
+
var inserted = [];
|
|
85
|
+
var updated = [];
|
|
86
|
+
var deleted = [];
|
|
87
|
+
for (var _i = 0, _objects = objects; _i < _objects.length; _i++) {
|
|
88
|
+
var object = _objects[_i];
|
|
89
|
+
if (object.status === "new") {
|
|
90
|
+
inserted.push(object);
|
|
91
|
+
} else if (object.status === "deleted") {
|
|
92
|
+
deleted.push(object);
|
|
93
|
+
} else if (object.status === "old" && _this.hasChanged(type, object.object)) {
|
|
94
|
+
updated.push(object);
|
|
95
|
+
} // Nothing for mock objects
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
inserted: inserted,
|
|
99
|
+
updated: updated,
|
|
100
|
+
deleted: deleted
|
|
101
|
+
};
|
|
102
|
+
});
|
|
77
103
|
_defineProperty(this, "refreshObjectByType", function (type) {
|
|
78
104
|
var force = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
79
105
|
return _this._getPromise(type).then(function () {
|
|
@@ -174,8 +200,14 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
174
200
|
throw new Error("The provided status is not valid");
|
|
175
201
|
}
|
|
176
202
|
if (status === "mock") {
|
|
203
|
+
wrapper.isMock = function () {
|
|
204
|
+
return true;
|
|
205
|
+
};
|
|
177
206
|
wrapper.insert = function () {
|
|
178
207
|
_this.models[type].storedObjects[id].status = "new";
|
|
208
|
+
wrapper.isMock = function () {
|
|
209
|
+
return false;
|
|
210
|
+
};
|
|
179
211
|
_this.update([wrapper]);
|
|
180
212
|
delete wrapper.insert;
|
|
181
213
|
};
|
|
@@ -359,6 +391,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
359
391
|
key: "hasChanged",
|
|
360
392
|
value: function hasChanged(type, object) {
|
|
361
393
|
var _this8 = this;
|
|
394
|
+
this._validateTypeInput(type);
|
|
362
395
|
var _hasChanged = function _hasChanged(type, object) {
|
|
363
396
|
var obj = _this8.models[type].storedObjects[object.getId()];
|
|
364
397
|
return !obj || obj.fingerprint !== obj.object.getFingerprint();
|
|
@@ -366,8 +399,12 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
366
399
|
if (object) {
|
|
367
400
|
return _hasChanged(type, object);
|
|
368
401
|
} else {
|
|
369
|
-
|
|
370
|
-
|
|
402
|
+
var _this$_getDiffSync = this._getDiffSync(type),
|
|
403
|
+
inserted = _this$_getDiffSync.inserted,
|
|
404
|
+
updated = _this$_getDiffSync.updated,
|
|
405
|
+
deleted = _this$_getDiffSync.deleted;
|
|
406
|
+
return [inserted, updated, deleted].some(function (i) {
|
|
407
|
+
return i.length > 0;
|
|
371
408
|
});
|
|
372
409
|
}
|
|
373
410
|
}
|
|
@@ -380,26 +417,9 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
380
417
|
key: "getDiff",
|
|
381
418
|
value: function getDiff(type, ifLoaded) {
|
|
382
419
|
var _this9 = this;
|
|
420
|
+
this._validateTypeInput(type);
|
|
383
421
|
return this._getPromise(type, ifLoaded).then(function () {
|
|
384
|
-
|
|
385
|
-
var inserted = [];
|
|
386
|
-
var updated = [];
|
|
387
|
-
var deleted = [];
|
|
388
|
-
for (var _i = 0, _objects = objects; _i < _objects.length; _i++) {
|
|
389
|
-
var object = _objects[_i];
|
|
390
|
-
if (object.status === "new") {
|
|
391
|
-
inserted.push(object);
|
|
392
|
-
} else if (object.status === "deleted") {
|
|
393
|
-
deleted.push(object);
|
|
394
|
-
} else if (object.status === "old" && _this9.hasChanged(type, object.object)) {
|
|
395
|
-
updated.push(object);
|
|
396
|
-
} // Nothing for mock objects
|
|
397
|
-
}
|
|
398
|
-
return {
|
|
399
|
-
inserted: inserted,
|
|
400
|
-
updated: updated,
|
|
401
|
-
deleted: deleted
|
|
402
|
-
};
|
|
422
|
+
return _this9._getDiffSync(type);
|
|
403
423
|
});
|
|
404
424
|
}
|
|
405
425
|
}, {
|
|
@@ -450,6 +470,20 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
450
470
|
return this.models[type].promise;
|
|
451
471
|
}
|
|
452
472
|
}
|
|
473
|
+
}, {
|
|
474
|
+
key: "getCollection",
|
|
475
|
+
value: function getCollection(type) {
|
|
476
|
+
var _this12 = this;
|
|
477
|
+
return this._getPromise(type).then(function () {
|
|
478
|
+
return Object.values(_this12.models[type].storedObjects).map(function (i) {
|
|
479
|
+
return i.object;
|
|
480
|
+
}).sort(function (a, b) {
|
|
481
|
+
return a.getId().localeCompare(b.getId());
|
|
482
|
+
}).map(function (i) {
|
|
483
|
+
return i.toJSON();
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
}
|
|
453
487
|
}]);
|
|
454
488
|
}();
|
|
455
489
|
function _error(error) {
|
|
@@ -458,9 +492,9 @@ function _error(error) {
|
|
|
458
492
|
return Promise.reject(error);
|
|
459
493
|
}
|
|
460
494
|
function _deleteByFilter(type, filterFunction) {
|
|
461
|
-
var
|
|
495
|
+
var _this13 = this;
|
|
462
496
|
return this._getPromise(type).then(function () {
|
|
463
|
-
var deleted = Object.values(
|
|
497
|
+
var deleted = Object.values(_this13.models[type].storedObjects).filter(function (i) {
|
|
464
498
|
return filterFunction(i.object);
|
|
465
499
|
});
|
|
466
500
|
var _iterator5 = _createForOfIteratorHelper(deleted),
|
|
@@ -481,7 +515,7 @@ function _deleteByFilter(type, filterFunction) {
|
|
|
481
515
|
});
|
|
482
516
|
}
|
|
483
517
|
function _loadObjects(type) {
|
|
484
|
-
var
|
|
518
|
+
var _this14 = this;
|
|
485
519
|
var item = this.models[type];
|
|
486
520
|
this.pubSub.publish("loading", {
|
|
487
521
|
status: "start",
|
|
@@ -493,14 +527,14 @@ function _loadObjects(type) {
|
|
|
493
527
|
try {
|
|
494
528
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
495
529
|
var _item2 = _step6.value;
|
|
496
|
-
_classPrivateFieldGet(_insertObject,
|
|
530
|
+
_classPrivateFieldGet(_insertObject, _this14).call(_this14, type, _item2, "old");
|
|
497
531
|
}
|
|
498
532
|
} catch (err) {
|
|
499
533
|
_iterator6.e(err);
|
|
500
534
|
} finally {
|
|
501
535
|
_iterator6.f();
|
|
502
536
|
}
|
|
503
|
-
|
|
537
|
+
_this14.pubSub.publish("loading", {
|
|
504
538
|
status: "end",
|
|
505
539
|
model: type
|
|
506
540
|
});
|