dataflux 1.9.1 → 1.9.4
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/dist/Model.js +4 -2
- package/dist/ObserverStore.js +105 -53
- package/dist/PersistentStore.js +6 -2
- package/dist/Store.js +108 -116
- package/dist/dataflux.min.js +1 -1
- package/dist/dataflux.min.js.map +1 -1
- package/package.json +16 -16
package/dist/Model.js
CHANGED
|
@@ -416,7 +416,9 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
416
416
|
value: function value(objects) {
|
|
417
417
|
var operation = "insert";
|
|
418
418
|
return (0, _modelHooksUtils.executeHook)(operation, _classPrivateFieldGet(_this, _insertHook), _classPrivateFieldGet(_this, _unWrap).call(_this, objects), _classPrivateFieldGet(_this, _axios)).then(function (data) {
|
|
419
|
-
if (data)
|
|
419
|
+
if (data) {
|
|
420
|
+
_classPrivateFieldGet(_this, _assignId).call(_this, data, objects);
|
|
421
|
+
}
|
|
420
422
|
|
|
421
423
|
_classPrivateFieldGet(_this, _cleanApiError).call(_this, objects);
|
|
422
424
|
|
|
@@ -432,7 +434,7 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
432
434
|
_classPrivateFieldInitSpec(this, _assignId, {
|
|
433
435
|
writable: true,
|
|
434
436
|
value: function value(data, objects) {
|
|
435
|
-
if (data.length === 1) {
|
|
437
|
+
if (data.length === 1 && objects.length === 1) {
|
|
436
438
|
var newId = data[0].id;
|
|
437
439
|
objects[0].setId(newId);
|
|
438
440
|
delete objects[0].setId;
|
package/dist/ObserverStore.js
CHANGED
|
@@ -81,8 +81,12 @@ var _getUniqueSubs = /*#__PURE__*/new WeakMap();
|
|
|
81
81
|
|
|
82
82
|
var _propagateChange = /*#__PURE__*/new WeakMap();
|
|
83
83
|
|
|
84
|
+
var _appendIfNotExistent = /*#__PURE__*/new WeakMap();
|
|
85
|
+
|
|
84
86
|
var _subscribeToObjects = /*#__PURE__*/new WeakMap();
|
|
85
87
|
|
|
88
|
+
var _merge = /*#__PURE__*/new WeakMap();
|
|
89
|
+
|
|
86
90
|
var _propagateInsertChange = /*#__PURE__*/new WeakSet();
|
|
87
91
|
|
|
88
92
|
var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
@@ -165,40 +169,41 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
165
169
|
});
|
|
166
170
|
|
|
167
171
|
_defineProperty(_assertThisInitialized(_this), "unsubscribe", function (key) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
_step;
|
|
172
|
+
_classPrivateFieldSet(_assertThisInitialized(_this), _unsubPromises, (_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises).length ? Promise.all(_classPrivateFieldGet(_assertThisInitialized(_this), _queryPromises)) : Promise.resolve()).then(function () {
|
|
173
|
+
if (_this._multipleSubscribed[key]) {
|
|
174
|
+
var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
|
|
175
|
+
_step;
|
|
173
176
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
try {
|
|
178
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
179
|
+
var sub = _step.value;
|
|
177
180
|
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
} catch (err) {
|
|
181
|
-
_iterator.e(err);
|
|
182
|
-
} finally {
|
|
183
|
-
_iterator.f();
|
|
181
|
+
_this.unsubscribe(sub);
|
|
184
182
|
}
|
|
183
|
+
} catch (err) {
|
|
184
|
+
_iterator.e(err);
|
|
185
|
+
} finally {
|
|
186
|
+
_iterator.f();
|
|
187
|
+
}
|
|
185
188
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
189
|
+
delete _this._multipleSubscribed[key];
|
|
190
|
+
} else {
|
|
191
|
+
for (var type in _this._subscribed) {
|
|
192
|
+
for (var id in _this._subscribed[type]) {
|
|
193
|
+
_this._subscribed[type][id] = _this._subscribed[type][id].filter(function (i) {
|
|
194
|
+
return i.subKey !== key;
|
|
195
|
+
});
|
|
196
|
+
_this._subscribed[type]["*"] = _this._subscribed[type]["*"].filter(function (i) {
|
|
197
|
+
return i.subKey !== key;
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
if (_this._subscribed[type][id].length === 0) {
|
|
201
|
+
delete _this._subscribed[type][id];
|
|
197
202
|
}
|
|
198
203
|
}
|
|
199
204
|
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
205
|
+
}
|
|
206
|
+
}));
|
|
202
207
|
});
|
|
203
208
|
|
|
204
209
|
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _getUniqueSubs, {
|
|
@@ -264,32 +269,98 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
264
269
|
}
|
|
265
270
|
});
|
|
266
271
|
|
|
272
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _appendIfNotExistent, {
|
|
273
|
+
writable: true,
|
|
274
|
+
value: function value(arr, item) {
|
|
275
|
+
if (Object.values(arr).filter(function (_ref4) {
|
|
276
|
+
var subKey = _ref4.subKey;
|
|
277
|
+
return item.subKey === subKey;
|
|
278
|
+
}).length === 0) {
|
|
279
|
+
arr.push(item);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
267
284
|
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _subscribeToObjects, {
|
|
268
285
|
writable: true,
|
|
269
286
|
value: function value(type, objectsToSubscribe, item) {
|
|
287
|
+
var _this$_subscribed$typ2, _, _this$_subscribed$typ3;
|
|
288
|
+
|
|
270
289
|
var _iterator4 = _createForOfIteratorHelper(objectsToSubscribe),
|
|
271
290
|
_step4;
|
|
272
291
|
|
|
273
292
|
try {
|
|
274
293
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
275
|
-
var _this$_subscribed$
|
|
294
|
+
var _this$_subscribed$typ4, _this$_subscribed$typ5;
|
|
276
295
|
|
|
277
296
|
var object = _step4.value;
|
|
278
297
|
var id = object.getId();
|
|
279
|
-
(_this$_subscribed$
|
|
298
|
+
(_this$_subscribed$typ5 = (_this$_subscribed$typ4 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ5 !== void 0 ? _this$_subscribed$typ5 : _this$_subscribed$typ4[id] = [];
|
|
280
299
|
|
|
281
|
-
_this._subscribed[type][id]
|
|
300
|
+
_classPrivateFieldGet(_assertThisInitialized(_this), _appendIfNotExistent).call(_assertThisInitialized(_this), _this._subscribed[type][id], item);
|
|
282
301
|
}
|
|
283
302
|
} catch (err) {
|
|
284
303
|
_iterator4.e(err);
|
|
285
304
|
} finally {
|
|
286
305
|
_iterator4.f();
|
|
287
306
|
}
|
|
307
|
+
|
|
308
|
+
(_this$_subscribed$typ3 = (_this$_subscribed$typ2 = _this._subscribed[type])[_ = "*"]) !== null && _this$_subscribed$typ3 !== void 0 ? _this$_subscribed$typ3 : _this$_subscribed$typ2[_] = [];
|
|
309
|
+
|
|
310
|
+
_classPrivateFieldGet(_assertThisInitialized(_this), _appendIfNotExistent).call(_assertThisInitialized(_this), _this._subscribed[type]["*"], item);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
_defineProperty(_assertThisInitialized(_this), "refresh", function (type) {
|
|
315
|
+
var refreshByType = function refreshByType(type) {
|
|
316
|
+
_this.pubSub.publish("refresh", {
|
|
317
|
+
status: "start",
|
|
318
|
+
model: type
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
return _this.refreshObjectByType(type).then(function (_ref5) {
|
|
322
|
+
var _ref6 = _slicedToArray(_ref5, 3),
|
|
323
|
+
inserted = _ref6[0],
|
|
324
|
+
updated = _ref6[1],
|
|
325
|
+
deleted = _ref6[2];
|
|
326
|
+
|
|
327
|
+
var item = _this.models[type];
|
|
328
|
+
return Promise.all([_classPrivateMethodGet(_assertThisInitialized(_this), _propagateInsertChange, _propagateInsertChange2).call(_assertThisInitialized(_this), type, inserted), _classPrivateFieldGet(_assertThisInitialized(_this), _propagateChange).call(_assertThisInitialized(_this), updated), _classPrivateFieldGet(_assertThisInitialized(_this), _propagateChange).call(_assertThisInitialized(_this), deleted)]).then(function () {
|
|
329
|
+
_this.pubSub.publish("refresh", {
|
|
330
|
+
status: "end",
|
|
331
|
+
model: type
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
return item.promise;
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
if (type) {
|
|
340
|
+
return refreshByType(type);
|
|
341
|
+
} else {
|
|
342
|
+
return Promise.all(Object.keys(_this.models).map(refreshByType));
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _merge, {
|
|
347
|
+
writable: true,
|
|
348
|
+
value: function value(originalObject, newObject) {
|
|
349
|
+
for (var key in newObject) {
|
|
350
|
+
originalObject[key] = newObject[key];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
originalObject.update();
|
|
288
354
|
}
|
|
289
355
|
});
|
|
290
356
|
|
|
291
357
|
_this._subscribed = {};
|
|
292
358
|
_this._multipleSubscribed = {};
|
|
359
|
+
|
|
360
|
+
if (options.autoRefresh && typeof options.autoRefresh === "number") {
|
|
361
|
+
setInterval(_this.refresh, options.autoRefresh);
|
|
362
|
+
}
|
|
363
|
+
|
|
293
364
|
return _this;
|
|
294
365
|
}
|
|
295
366
|
|
|
@@ -362,34 +433,15 @@ function _propagateInsertChange2(type, newObjects) {
|
|
|
362
433
|
}
|
|
363
434
|
|
|
364
435
|
var possibleSubs = Object.values(uniqueSubs);
|
|
365
|
-
(0, _batchPromises["default"])(10, possibleSubs, function (
|
|
366
|
-
var callback =
|
|
367
|
-
filterFunction =
|
|
436
|
+
(0, _batchPromises["default"])(10, possibleSubs, function (_ref7) {
|
|
437
|
+
var callback = _ref7.callback,
|
|
438
|
+
filterFunction = _ref7.filterFunction,
|
|
439
|
+
subKey = _ref7.subKey;
|
|
368
440
|
var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
|
|
369
441
|
|
|
370
442
|
if (objectsToSubscribe.length) {
|
|
371
443
|
// Check if the new objects matter
|
|
372
444
|
return _this4.find(type, filterFunction).then(function (data) {
|
|
373
|
-
var subKey;
|
|
374
|
-
|
|
375
|
-
var _iterator6 = _createForOfIteratorHelper(data),
|
|
376
|
-
_step6;
|
|
377
|
-
|
|
378
|
-
try {
|
|
379
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
380
|
-
var d = _step6.value;
|
|
381
|
-
|
|
382
|
-
var item = _this4._subscribed[d.getModel().getType()][d.getId()];
|
|
383
|
-
|
|
384
|
-
subKey = item ? item.subKey : null;
|
|
385
|
-
if (subKey) break;
|
|
386
|
-
}
|
|
387
|
-
} catch (err) {
|
|
388
|
-
_iterator6.e(err);
|
|
389
|
-
} finally {
|
|
390
|
-
_iterator6.f();
|
|
391
|
-
}
|
|
392
|
-
|
|
393
445
|
_classPrivateFieldGet(_this4, _subscribeToObjects).call(_this4, type, objectsToSubscribe, {
|
|
394
446
|
callback: callback,
|
|
395
447
|
filterFunction: filterFunction,
|
package/dist/PersistentStore.js
CHANGED
|
@@ -155,10 +155,14 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
|
|
|
155
155
|
return new Promise(function (resolve, reject) {
|
|
156
156
|
if (_this.options.autoSave) {
|
|
157
157
|
if (_this._delayedSaveTimer) {
|
|
158
|
-
_this._delayedSavePromise
|
|
158
|
+
if (_this._delayedSavePromise) {
|
|
159
|
+
_this._delayedSavePromise();
|
|
160
|
+
|
|
161
|
+
_this._delayedSavePromise = null;
|
|
162
|
+
}
|
|
159
163
|
|
|
160
|
-
_this._delayedSavePromise = null;
|
|
161
164
|
clearTimeout(_this._delayedSaveTimer);
|
|
165
|
+
_this._delayedSaveTimer = null;
|
|
162
166
|
}
|
|
163
167
|
|
|
164
168
|
_this._delayedSavePromise = resolve;
|
package/dist/Store.js
CHANGED
|
@@ -43,8 +43,6 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
|
|
|
43
43
|
|
|
44
44
|
var objectStatuses = ["new", "old", "mock", "deleted"];
|
|
45
45
|
|
|
46
|
-
var _refreshObjectByType = /*#__PURE__*/new WeakMap();
|
|
47
|
-
|
|
48
46
|
var _merge = /*#__PURE__*/new WeakMap();
|
|
49
47
|
|
|
50
48
|
var _error = /*#__PURE__*/new WeakSet();
|
|
@@ -55,7 +53,7 @@ var _deleteByFilter = /*#__PURE__*/new WeakSet();
|
|
|
55
53
|
|
|
56
54
|
var _getPromise = /*#__PURE__*/new WeakSet();
|
|
57
55
|
|
|
58
|
-
var _insertObject = /*#__PURE__*/new
|
|
56
|
+
var _insertObject = /*#__PURE__*/new WeakMap();
|
|
59
57
|
|
|
60
58
|
var _loadObjects = /*#__PURE__*/new WeakSet();
|
|
61
59
|
|
|
@@ -71,8 +69,6 @@ var Store = /*#__PURE__*/function () {
|
|
|
71
69
|
|
|
72
70
|
_classPrivateMethodInitSpec(this, _loadObjects);
|
|
73
71
|
|
|
74
|
-
_classPrivateMethodInitSpec(this, _insertObject);
|
|
75
|
-
|
|
76
72
|
_classPrivateMethodInitSpec(this, _getPromise);
|
|
77
73
|
|
|
78
74
|
_classPrivateMethodInitSpec(this, _deleteByFilter);
|
|
@@ -83,80 +79,80 @@ var Store = /*#__PURE__*/function () {
|
|
|
83
79
|
return Object.keys(_this.models);
|
|
84
80
|
});
|
|
85
81
|
|
|
86
|
-
_defineProperty(this, "
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
_defineProperty(this, "refreshObjectByType", function (type) {
|
|
83
|
+
return _classPrivateMethodGet(_this, _getPromise, _getPromise2).call(_this, type).then(function () {
|
|
84
|
+
var item = _this.models[type];
|
|
85
|
+
var inserted = [];
|
|
86
|
+
var deleted = [];
|
|
87
|
+
var updated = [];
|
|
88
|
+
item.promise = item.model.retrieveAll()["catch"](function () {
|
|
89
|
+
var objects = Object.values(_this.models[type].storedObjects);
|
|
90
|
+
var list = [];
|
|
91
|
+
return (0, _batchPromises["default"])(4, objects, function (object) {
|
|
92
|
+
return item.model.factory(object.object).then(function (items) {
|
|
93
|
+
list = list.concat(items);
|
|
94
|
+
});
|
|
95
|
+
}).then(function () {
|
|
96
|
+
return list;
|
|
97
|
+
});
|
|
98
|
+
}).then(function (objects) {
|
|
99
|
+
var _iterator = _createForOfIteratorHelper(objects),
|
|
100
|
+
_step;
|
|
93
101
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var item = _this.models[type];
|
|
102
|
+
try {
|
|
103
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
104
|
+
var object = _step.value;
|
|
105
|
+
var wrapper = new _Obj["default"](object, item.model);
|
|
99
106
|
|
|
100
|
-
|
|
101
|
-
status: "start",
|
|
102
|
-
model: type
|
|
103
|
-
});
|
|
107
|
+
var _id = wrapper.getId();
|
|
104
108
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
var wrapper = new _Obj["default"](object, item.model);
|
|
123
|
-
var id = wrapper.getId();
|
|
124
|
-
var currentObject = item === null || item === void 0 ? void 0 : item.storedObjects[id]; // console.log("currentObject", item);
|
|
125
|
-
|
|
126
|
-
if (currentObject) {
|
|
127
|
-
var newFingerprint = wrapper.getFingerprint();
|
|
128
|
-
var oldFingerprint = currentObject.fingerprint;
|
|
129
|
-
|
|
130
|
-
if (oldFingerprint !== newFingerprint) {
|
|
131
|
-
// Nothing to do otherwise
|
|
132
|
-
if (_this.hasChanged(type, currentObject.object)) {// Was the object edited locally?
|
|
133
|
-
// Nothing for now
|
|
134
|
-
} else {
|
|
135
|
-
// Update with the new object
|
|
136
|
-
// console.log("merge", wrapper);
|
|
137
|
-
_classPrivateFieldGet(_this, _merge).call(_this, _this.models[type].storedObjects[id].object, wrapper.toJSON());
|
|
138
|
-
|
|
139
|
-
_this.models[type].storedObjects[id].fingerprint = newFingerprint;
|
|
140
|
-
}
|
|
109
|
+
var currentObject = item === null || item === void 0 ? void 0 : item.storedObjects[_id];
|
|
110
|
+
|
|
111
|
+
if (currentObject) {
|
|
112
|
+
currentObject.deleted = false;
|
|
113
|
+
var newFingerprint = wrapper.getFingerprint();
|
|
114
|
+
var oldFingerprint = currentObject.fingerprint;
|
|
115
|
+
|
|
116
|
+
if (oldFingerprint !== newFingerprint) {
|
|
117
|
+
// Nothing to do otherwise
|
|
118
|
+
if (_this.hasChanged(type, currentObject.object)) {// Was the object edited locally?
|
|
119
|
+
// Nothing for now
|
|
120
|
+
} else {
|
|
121
|
+
// Update with the new object
|
|
122
|
+
_classPrivateFieldGet(_this, _merge).call(_this, currentObject.object, wrapper.toJSON());
|
|
123
|
+
|
|
124
|
+
currentObject.fingerprint = newFingerprint;
|
|
125
|
+
updated.push(currentObject.object);
|
|
141
126
|
}
|
|
142
|
-
} else {
|
|
143
|
-
_classPrivateMethodGet(_this, _insertObject, _insertObject2).call(_this, type, object, "old");
|
|
144
127
|
}
|
|
128
|
+
} else {
|
|
129
|
+
var newObject = _classPrivateFieldGet(_this, _insertObject).call(_this, type, object, "old");
|
|
130
|
+
|
|
131
|
+
item.storedObjects[newObject.getId()].deleted = false;
|
|
132
|
+
inserted.push(newObject);
|
|
145
133
|
}
|
|
146
|
-
} catch (err) {
|
|
147
|
-
_iterator.e(err);
|
|
148
|
-
} finally {
|
|
149
|
-
_iterator.f();
|
|
150
134
|
}
|
|
135
|
+
} catch (err) {
|
|
136
|
+
_iterator.e(err);
|
|
137
|
+
} finally {
|
|
138
|
+
_iterator.f();
|
|
139
|
+
}
|
|
151
140
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
141
|
+
for (var id in item === null || item === void 0 ? void 0 : item.storedObjects) {
|
|
142
|
+
var obj = item.storedObjects[id];
|
|
143
|
+
|
|
144
|
+
if (obj.deleted === undefined) {
|
|
145
|
+
deleted.push(obj.object);
|
|
146
|
+
delete item.storedObjects[id];
|
|
147
|
+
} else {
|
|
148
|
+
delete obj.deleted;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return [inserted, updated, deleted];
|
|
158
153
|
});
|
|
159
|
-
|
|
154
|
+
return item.promise;
|
|
155
|
+
});
|
|
160
156
|
});
|
|
161
157
|
|
|
162
158
|
_classPrivateFieldInitSpec(this, _merge, {
|
|
@@ -164,9 +160,8 @@ var Store = /*#__PURE__*/function () {
|
|
|
164
160
|
value: function value(originalObject, newObject) {
|
|
165
161
|
for (var key in newObject) {
|
|
166
162
|
originalObject[key] = newObject[key];
|
|
167
|
-
}
|
|
163
|
+
} // originalObject.update();
|
|
168
164
|
|
|
169
|
-
originalObject.update();
|
|
170
165
|
}
|
|
171
166
|
});
|
|
172
167
|
|
|
@@ -183,6 +178,41 @@ var Store = /*#__PURE__*/function () {
|
|
|
183
178
|
}
|
|
184
179
|
});
|
|
185
180
|
|
|
181
|
+
_classPrivateFieldInitSpec(this, _insertObject, {
|
|
182
|
+
writable: true,
|
|
183
|
+
value: function value(type, item, status) {
|
|
184
|
+
var model = _this.models[type].model;
|
|
185
|
+
var wrapper = new _Obj["default"](item, model);
|
|
186
|
+
var id = wrapper.getId();
|
|
187
|
+
|
|
188
|
+
if (_this.models[type].storedObjects[id]) {
|
|
189
|
+
throw new Error("The IDs provided for the model ".concat(type, " are not unique"));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!objectStatuses.includes(status)) {
|
|
193
|
+
throw new Error("The provided status is not valid");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (status === "mock") {
|
|
197
|
+
wrapper.insert = function () {
|
|
198
|
+
_this.models[type].storedObjects[id].status = "new";
|
|
199
|
+
|
|
200
|
+
_this.update([wrapper]);
|
|
201
|
+
|
|
202
|
+
delete wrapper.insert;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
_this.models[type].storedObjects[id] = {
|
|
207
|
+
id: id,
|
|
208
|
+
fingerprint: wrapper.getFingerprint(),
|
|
209
|
+
object: wrapper,
|
|
210
|
+
status: status
|
|
211
|
+
};
|
|
212
|
+
return wrapper;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
186
216
|
this.options = {
|
|
187
217
|
autoSave: (_options$autoSave = options.autoSave) !== null && _options$autoSave !== void 0 ? _options$autoSave : true,
|
|
188
218
|
saveDelay: options.saveDelay || 1000,
|
|
@@ -191,10 +221,6 @@ var Store = /*#__PURE__*/function () {
|
|
|
191
221
|
};
|
|
192
222
|
this.models = {};
|
|
193
223
|
this.pubSub = new _PubSub["default"]();
|
|
194
|
-
|
|
195
|
-
if (this.options.autoRefresh && typeof this.options.autoRefresh === "number") {
|
|
196
|
-
setInterval(this.refresh, this.options.autoRefresh);
|
|
197
|
-
}
|
|
198
224
|
}
|
|
199
225
|
|
|
200
226
|
_createClass(Store, [{
|
|
@@ -274,7 +300,7 @@ var Store = /*#__PURE__*/function () {
|
|
|
274
300
|
|
|
275
301
|
return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
|
|
276
302
|
return objects.map(function (object) {
|
|
277
|
-
return
|
|
303
|
+
return _classPrivateFieldGet(_this3, _insertObject).call(_this3, type, object, "new");
|
|
278
304
|
});
|
|
279
305
|
});
|
|
280
306
|
}
|
|
@@ -285,7 +311,7 @@ var Store = /*#__PURE__*/function () {
|
|
|
285
311
|
|
|
286
312
|
return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
|
|
287
313
|
return objects.map(function (object) {
|
|
288
|
-
return
|
|
314
|
+
return _classPrivateFieldGet(_this4, _insertObject).call(_this4, type, object, "mock");
|
|
289
315
|
});
|
|
290
316
|
});
|
|
291
317
|
}
|
|
@@ -438,7 +464,7 @@ var Store = /*#__PURE__*/function () {
|
|
|
438
464
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
439
465
|
var _item = _step4.value;
|
|
440
466
|
|
|
441
|
-
|
|
467
|
+
_classPrivateFieldGet(_this9, _insertObject).call(_this9, type, _item, "old");
|
|
442
468
|
}
|
|
443
469
|
} catch (err) {
|
|
444
470
|
_iterator4.e(err);
|
|
@@ -510,42 +536,8 @@ function _getPromise2(type) {
|
|
|
510
536
|
}
|
|
511
537
|
}
|
|
512
538
|
|
|
513
|
-
function _insertObject2(type, item, status) {
|
|
514
|
-
var _this12 = this;
|
|
515
|
-
|
|
516
|
-
var model = this.models[type].model;
|
|
517
|
-
var wrapper = new _Obj["default"](item, model);
|
|
518
|
-
var id = wrapper.getId();
|
|
519
|
-
|
|
520
|
-
if (this.models[type].storedObjects[id]) {
|
|
521
|
-
throw new Error("The IDs provided for the model ".concat(type, " are not unique"));
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
if (!objectStatuses.includes(status)) {
|
|
525
|
-
throw new Error("The provided status is not valid");
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
if (status === "mock") {
|
|
529
|
-
wrapper.insert = function () {
|
|
530
|
-
_this12.models[type].storedObjects[id].status = "new";
|
|
531
|
-
|
|
532
|
-
_this12.update([wrapper]);
|
|
533
|
-
|
|
534
|
-
delete wrapper.insert;
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
this.models[type].storedObjects[id] = {
|
|
539
|
-
id: id,
|
|
540
|
-
fingerprint: wrapper.getFingerprint(),
|
|
541
|
-
object: wrapper,
|
|
542
|
-
status: status
|
|
543
|
-
};
|
|
544
|
-
return wrapper;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
539
|
function _loadObjects2(type) {
|
|
548
|
-
var
|
|
540
|
+
var _this12 = this;
|
|
549
541
|
|
|
550
542
|
var item = this.models[type];
|
|
551
543
|
this.pubSub.publish("loading", {
|
|
@@ -560,7 +552,7 @@ function _loadObjects2(type) {
|
|
|
560
552
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
561
553
|
var _item2 = _step6.value;
|
|
562
554
|
|
|
563
|
-
|
|
555
|
+
_classPrivateFieldGet(_this12, _insertObject).call(_this12, type, _item2, "old");
|
|
564
556
|
}
|
|
565
557
|
} catch (err) {
|
|
566
558
|
_iterator6.e(err);
|
|
@@ -568,7 +560,7 @@ function _loadObjects2(type) {
|
|
|
568
560
|
_iterator6.f();
|
|
569
561
|
}
|
|
570
562
|
|
|
571
|
-
|
|
563
|
+
_this12.pubSub.publish("loading", {
|
|
572
564
|
status: "end",
|
|
573
565
|
model: type
|
|
574
566
|
});
|