dataflux 1.0.4 → 1.1.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 +188 -130
- package/dist/Model.js +186 -60
- package/dist/ObserverStore.js +178 -131
- package/dist/PersistentStore.js +107 -75
- package/dist/PubSub.js +59 -0
- package/dist/Store.js +283 -152
- package/dist/fingerprint.js +11 -13
- package/dist/modelHooksUtils.js +31 -14
- package/package.json +5 -5
package/dist/ObserverStore.js
CHANGED
|
@@ -21,11 +21,15 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
21
21
|
|
|
22
22
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
23
|
|
|
24
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
|
+
|
|
24
26
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
25
27
|
|
|
26
28
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
27
29
|
|
|
28
|
-
function
|
|
30
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
31
|
+
|
|
32
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
29
33
|
|
|
30
34
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
31
35
|
|
|
@@ -41,8 +45,30 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
41
45
|
|
|
42
46
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
43
47
|
|
|
48
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
49
|
+
|
|
50
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
51
|
+
|
|
52
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
53
|
+
|
|
44
54
|
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; }
|
|
45
55
|
|
|
56
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
57
|
+
|
|
58
|
+
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
59
|
+
|
|
60
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
61
|
+
|
|
62
|
+
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
63
|
+
|
|
64
|
+
var _getUniqueSubs = /*#__PURE__*/new WeakMap();
|
|
65
|
+
|
|
66
|
+
var _propagateChange = /*#__PURE__*/new WeakMap();
|
|
67
|
+
|
|
68
|
+
var _subscribeToObjects = /*#__PURE__*/new WeakMap();
|
|
69
|
+
|
|
70
|
+
var _propagateInsertChange = /*#__PURE__*/new WeakSet();
|
|
71
|
+
|
|
46
72
|
var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
47
73
|
_inherits(ObserverStore, _PersistentStore);
|
|
48
74
|
|
|
@@ -55,15 +81,17 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
55
81
|
|
|
56
82
|
_this = _super.call(this, options);
|
|
57
83
|
|
|
84
|
+
_classPrivateMethodInitSpec(_assertThisInitialized(_this), _propagateInsertChange);
|
|
85
|
+
|
|
58
86
|
_defineProperty(_assertThisInitialized(_this), "subscribe", function (type, callback, filterFunction) {
|
|
59
87
|
var subKey = (0, _uuid.v4)();
|
|
60
88
|
|
|
61
|
-
if (!_this.
|
|
62
|
-
_this.
|
|
89
|
+
if (!_this._subscribed[type]) {
|
|
90
|
+
_this._subscribed[type] = {};
|
|
63
91
|
}
|
|
64
92
|
|
|
65
93
|
_this.find(type, filterFunction).then(function (data) {
|
|
66
|
-
_this.
|
|
94
|
+
_classPrivateFieldGet(_assertThisInitialized(_this), _subscribeToObjects).call(_assertThisInitialized(_this), type, data, {
|
|
67
95
|
callback: callback,
|
|
68
96
|
filterFunction: filterFunction,
|
|
69
97
|
subKey: subKey
|
|
@@ -76,185 +104,204 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
76
104
|
});
|
|
77
105
|
|
|
78
106
|
_defineProperty(_assertThisInitialized(_this), "unsubscribe", function (key) {
|
|
79
|
-
for (var type in _this.
|
|
80
|
-
for (var id in _this.
|
|
81
|
-
_this.
|
|
107
|
+
for (var type in _this._subscribed) {
|
|
108
|
+
for (var id in _this._subscribed[type]) {
|
|
109
|
+
_this._subscribed[type][id] = _this._subscribed[type][id].filter(function (i) {
|
|
82
110
|
return i.subKey !== key;
|
|
83
111
|
});
|
|
84
112
|
|
|
85
|
-
if (_this.
|
|
86
|
-
delete _this.
|
|
113
|
+
if (_this._subscribed[type][id].length === 0) {
|
|
114
|
+
delete _this._subscribed[type][id];
|
|
87
115
|
}
|
|
88
116
|
}
|
|
89
117
|
}
|
|
90
118
|
});
|
|
91
119
|
|
|
92
|
-
|
|
93
|
-
|
|
120
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _getUniqueSubs, {
|
|
121
|
+
writable: true,
|
|
122
|
+
value: function value(objects, type) {
|
|
123
|
+
var out = {};
|
|
94
124
|
|
|
95
|
-
|
|
96
|
-
|
|
125
|
+
var _iterator = _createForOfIteratorHelper(objects),
|
|
126
|
+
_step;
|
|
97
127
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
128
|
+
try {
|
|
129
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
130
|
+
var object = _step.value;
|
|
131
|
+
var objectId = object.getId();
|
|
132
|
+
var typeChannel = _this._subscribed[type] || {};
|
|
133
|
+
var subscribedToObject = typeChannel[objectId] || [];
|
|
104
134
|
|
|
105
|
-
|
|
106
|
-
|
|
135
|
+
var _iterator2 = _createForOfIteratorHelper(subscribedToObject),
|
|
136
|
+
_step2;
|
|
107
137
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
138
|
+
try {
|
|
139
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
140
|
+
var sub = _step2.value;
|
|
141
|
+
out[sub.subKey] = out[sub.subKey] || sub;
|
|
142
|
+
}
|
|
143
|
+
} catch (err) {
|
|
144
|
+
_iterator2.e(err);
|
|
145
|
+
} finally {
|
|
146
|
+
_iterator2.f();
|
|
112
147
|
}
|
|
113
|
-
} catch (err) {
|
|
114
|
-
_iterator2.e(err);
|
|
115
|
-
} finally {
|
|
116
|
-
_iterator2.f();
|
|
117
148
|
}
|
|
149
|
+
} catch (err) {
|
|
150
|
+
_iterator.e(err);
|
|
151
|
+
} finally {
|
|
152
|
+
_iterator.f();
|
|
118
153
|
}
|
|
119
|
-
} catch (err) {
|
|
120
|
-
_iterator.e(err);
|
|
121
|
-
} finally {
|
|
122
|
-
_iterator.f();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return Object.values(out);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
_defineProperty(_assertThisInitialized(_this), "_propagateChange", function () {
|
|
129
|
-
var objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
130
|
-
|
|
131
|
-
if (objects.length) {
|
|
132
|
-
var type = objects[0].getModel().getType();
|
|
133
154
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
(0, _batchPromises["default"])(10, uniqueSubs, function (_ref) {
|
|
137
|
-
var callback = _ref.callback,
|
|
138
|
-
filterFunction = _ref.filterFunction;
|
|
139
|
-
return _this.find(type, filterFunction).then(callback);
|
|
140
|
-
});
|
|
155
|
+
return Object.values(out);
|
|
141
156
|
}
|
|
142
157
|
});
|
|
143
158
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
159
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _propagateChange, {
|
|
160
|
+
writable: true,
|
|
161
|
+
value: function value() {
|
|
162
|
+
var objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
147
163
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var object = _step3.value;
|
|
151
|
-
var id = object.getId();
|
|
164
|
+
if (objects.length) {
|
|
165
|
+
var type = objects[0].getModel().getType();
|
|
152
166
|
|
|
153
|
-
|
|
154
|
-
_this.__subscribed[type][id] = [];
|
|
155
|
-
}
|
|
167
|
+
var uniqueSubs = _classPrivateFieldGet(_assertThisInitialized(_this), _getUniqueSubs).call(_assertThisInitialized(_this), objects, type);
|
|
156
168
|
|
|
157
|
-
|
|
169
|
+
(0, _batchPromises["default"])(10, uniqueSubs, function (_ref) {
|
|
170
|
+
var callback = _ref.callback,
|
|
171
|
+
filterFunction = _ref.filterFunction;
|
|
172
|
+
return _this.find(type, filterFunction).then(callback);
|
|
173
|
+
});
|
|
158
174
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
} finally {
|
|
162
|
-
_iterator3.f();
|
|
175
|
+
|
|
176
|
+
return objects;
|
|
163
177
|
}
|
|
164
178
|
});
|
|
165
179
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var object = _objects[_i];
|
|
172
|
-
|
|
173
|
-
var _iterator4 = _createForOfIteratorHelper(object),
|
|
174
|
-
_step4;
|
|
180
|
+
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _subscribeToObjects, {
|
|
181
|
+
writable: true,
|
|
182
|
+
value: function value(type, objectsToSubscribe, item) {
|
|
183
|
+
var _iterator3 = _createForOfIteratorHelper(objectsToSubscribe),
|
|
184
|
+
_step3;
|
|
175
185
|
|
|
176
186
|
try {
|
|
177
|
-
for (
|
|
178
|
-
var
|
|
187
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
188
|
+
var object = _step3.value;
|
|
189
|
+
var id = object.getId();
|
|
179
190
|
|
|
180
|
-
if (!
|
|
181
|
-
|
|
191
|
+
if (!_this._subscribed[type][id]) {
|
|
192
|
+
_this._subscribed[type][id] = [];
|
|
182
193
|
}
|
|
194
|
+
|
|
195
|
+
_this._subscribed[type][id].push(item);
|
|
183
196
|
}
|
|
184
197
|
} catch (err) {
|
|
185
|
-
|
|
198
|
+
_iterator3.e(err);
|
|
186
199
|
} finally {
|
|
187
|
-
|
|
200
|
+
_iterator3.f();
|
|
188
201
|
}
|
|
189
202
|
}
|
|
203
|
+
});
|
|
190
204
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
filterFunction = _ref2.filterFunction;
|
|
195
|
-
var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
|
|
205
|
+
_this._subscribed = {};
|
|
206
|
+
return _this;
|
|
207
|
+
}
|
|
196
208
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
209
|
+
_createClass(ObserverStore, [{
|
|
210
|
+
key: "update",
|
|
211
|
+
value: function update(objects) {
|
|
212
|
+
return _get(_getPrototypeOf(ObserverStore.prototype), "update", this).call(this, objects).then(_classPrivateFieldGet(this, _propagateChange));
|
|
213
|
+
}
|
|
214
|
+
}, {
|
|
215
|
+
key: "insert",
|
|
216
|
+
value: function insert(type, objects) {
|
|
217
|
+
var _this2 = this;
|
|
218
|
+
|
|
219
|
+
objects = Array.isArray(objects) ? objects : [objects];
|
|
220
|
+
return _get(_getPrototypeOf(ObserverStore.prototype), "insert", this).call(this, type, objects).then(function (objects) {
|
|
221
|
+
_classPrivateMethodGet(_this2, _propagateInsertChange, _propagateInsertChange2).call(_this2, type, objects);
|
|
222
|
+
|
|
223
|
+
return objects;
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}, {
|
|
227
|
+
key: "delete",
|
|
228
|
+
value: function _delete(typeOrObjects, filterFunction) {
|
|
229
|
+
return _get(_getPrototypeOf(ObserverStore.prototype), "delete", this).call(this, typeOrObjects, filterFunction).then(_classPrivateFieldGet(this, _propagateChange));
|
|
230
|
+
}
|
|
231
|
+
}]);
|
|
232
|
+
|
|
233
|
+
return ObserverStore;
|
|
234
|
+
}(_PersistentStore2["default"]);
|
|
201
235
|
|
|
202
|
-
|
|
203
|
-
|
|
236
|
+
function _propagateInsertChange2(type, newObjects) {
|
|
237
|
+
var _this3 = this;
|
|
204
238
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
239
|
+
if (this._subscribed[type]) {
|
|
240
|
+
var uniqueSubs = {};
|
|
241
|
+
var objects = Object.values(this._subscribed[type]);
|
|
208
242
|
|
|
209
|
-
|
|
243
|
+
for (var _i = 0, _objects = objects; _i < _objects.length; _i++) {
|
|
244
|
+
var object = _objects[_i];
|
|
210
245
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
} catch (err) {
|
|
215
|
-
_iterator5.e(err);
|
|
216
|
-
} finally {
|
|
217
|
-
_iterator5.f();
|
|
218
|
-
}
|
|
246
|
+
var _iterator4 = _createForOfIteratorHelper(object),
|
|
247
|
+
_step4;
|
|
219
248
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
subKey: subKey
|
|
224
|
-
});
|
|
249
|
+
try {
|
|
250
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
251
|
+
var sub = _step4.value;
|
|
225
252
|
|
|
226
|
-
|
|
227
|
-
|
|
253
|
+
if (!uniqueSubs[sub.subKey]) {
|
|
254
|
+
uniqueSubs[sub.subKey] = sub;
|
|
255
|
+
}
|
|
228
256
|
}
|
|
229
|
-
})
|
|
230
|
-
|
|
257
|
+
} catch (err) {
|
|
258
|
+
_iterator4.e(err);
|
|
259
|
+
} finally {
|
|
260
|
+
_iterator4.f();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
231
263
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
264
|
+
var possibleSubs = Object.values(uniqueSubs);
|
|
265
|
+
(0, _batchPromises["default"])(10, possibleSubs, function (_ref2) {
|
|
266
|
+
var callback = _ref2.callback,
|
|
267
|
+
filterFunction = _ref2.filterFunction;
|
|
268
|
+
var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
|
|
237
269
|
|
|
238
|
-
|
|
239
|
-
|
|
270
|
+
if (objectsToSubscribe.length) {
|
|
271
|
+
// Check if the new objects matter
|
|
272
|
+
return _this3.find(type, filterFunction).then(function (data) {
|
|
273
|
+
var subKey;
|
|
240
274
|
|
|
241
|
-
|
|
275
|
+
var _iterator5 = _createForOfIteratorHelper(data),
|
|
276
|
+
_step5;
|
|
242
277
|
|
|
243
|
-
|
|
244
|
-
|
|
278
|
+
try {
|
|
279
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
280
|
+
var d = _step5.value;
|
|
245
281
|
|
|
246
|
-
|
|
247
|
-
}
|
|
282
|
+
var item = _this3._subscribed[d.getModel().getType()][d.getId()];
|
|
248
283
|
|
|
249
|
-
|
|
250
|
-
|
|
284
|
+
subKey = item ? item.subKey : null;
|
|
285
|
+
if (subKey) break;
|
|
286
|
+
}
|
|
287
|
+
} catch (err) {
|
|
288
|
+
_iterator5.e(err);
|
|
289
|
+
} finally {
|
|
290
|
+
_iterator5.f();
|
|
291
|
+
}
|
|
251
292
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
293
|
+
_classPrivateFieldGet(_this3, _subscribeToObjects).call(_this3, type, objectsToSubscribe, {
|
|
294
|
+
callback: callback,
|
|
295
|
+
filterFunction: filterFunction,
|
|
296
|
+
subKey: subKey
|
|
297
|
+
});
|
|
255
298
|
|
|
256
|
-
|
|
257
|
-
}(
|
|
299
|
+
return data;
|
|
300
|
+
}).then(callback);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
}
|
|
258
305
|
|
|
259
306
|
var _default = ObserverStore;
|
|
260
307
|
exports["default"] = _default;
|
package/dist/PersistentStore.js
CHANGED
|
@@ -9,19 +9,19 @@ exports["default"] = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _Store2 = _interopRequireDefault(require("./Store"));
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
12
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
15
13
|
|
|
16
|
-
function
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
17
15
|
|
|
18
|
-
function
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
17
|
|
|
20
18
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
21
19
|
|
|
22
20
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
23
21
|
|
|
24
|
-
function
|
|
22
|
+
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
|
|
23
|
+
|
|
24
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
25
25
|
|
|
26
26
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
27
27
|
|
|
@@ -51,98 +51,130 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
|
|
|
51
51
|
|
|
52
52
|
_this = _super.call(this, options);
|
|
53
53
|
|
|
54
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
55
|
-
|
|
54
|
+
_defineProperty(_assertThisInitialized(_this), "save", function () {
|
|
55
|
+
_this._busy = true;
|
|
56
|
+
|
|
57
|
+
_this.pubSub.publish("save", "start");
|
|
58
|
+
|
|
59
|
+
return Promise.all(Object.keys(_this.models).map(_this._saveByType)).then(function (data) {
|
|
60
|
+
_this._busy = false;
|
|
61
|
+
|
|
62
|
+
_this.pubSub.publish("save", "end");
|
|
63
|
+
|
|
64
|
+
return data;
|
|
65
|
+
})["catch"](function (error) {
|
|
66
|
+
_this._busy = false;
|
|
67
|
+
|
|
68
|
+
_this.pubSub.publish("save", "end");
|
|
69
|
+
|
|
70
|
+
_this.pubSub.publish("error", error);
|
|
71
|
+
|
|
72
|
+
return Promise.reject(error);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
_defineProperty(_assertThisInitialized(_this), "_saveByType", function (type) {
|
|
77
|
+
return _this.getDiff(type).then(function (_ref) {
|
|
56
78
|
var inserted = _ref.inserted,
|
|
57
79
|
updated = _ref.updated,
|
|
58
80
|
deleted = _ref.deleted;
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
var model = _this.models[type].model; // Operations order:
|
|
82
|
+
// 1) insert
|
|
83
|
+
// 2) update
|
|
84
|
+
// 3) delete
|
|
85
|
+
|
|
86
|
+
return model.insertObjects(inserted).then(function () {
|
|
87
|
+
return _this.applyDiff({
|
|
88
|
+
inserted: inserted
|
|
89
|
+
}, type);
|
|
61
90
|
}).then(function () {
|
|
62
|
-
return
|
|
91
|
+
return model.updateObjects(updated);
|
|
63
92
|
}).then(function () {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
_iterator.e(err);
|
|
74
|
-
} finally {
|
|
75
|
-
_iterator.f();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
var _iterator2 = _createForOfIteratorHelper(updated.concat(inserted)),
|
|
79
|
-
_step2;
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
83
|
-
var _object = _step2.value;
|
|
84
|
-
_this.models[type].storedObjects[_object.id].fingerprint = _object.object.getFingerprint();
|
|
85
|
-
_this.models[type].storedObjects[_object.id].status = "old";
|
|
86
|
-
}
|
|
87
|
-
} catch (err) {
|
|
88
|
-
_iterator2.e(err);
|
|
89
|
-
} finally {
|
|
90
|
-
_iterator2.f();
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
_defineProperty(_assertThisInitialized(_this), "_getSets", function (type) {
|
|
97
|
-
return _this._getPromise(type).then(function () {
|
|
98
|
-
var objects = Object.values(_this.models[type].storedObjects);
|
|
99
|
-
var newObjects = objects.filter(function (object) {
|
|
100
|
-
return object.status === "new";
|
|
101
|
-
});
|
|
102
|
-
var edited = objects.filter(function (object) {
|
|
103
|
-
return object.status === "old" && object.fingerprint !== object.object.getFingerprint();
|
|
104
|
-
});
|
|
105
|
-
var deleted = objects.filter(function (object) {
|
|
106
|
-
return object.status === "deleted";
|
|
93
|
+
return _this.applyDiff({
|
|
94
|
+
updated: updated
|
|
95
|
+
}, type);
|
|
96
|
+
}).then(function () {
|
|
97
|
+
return model.deleteObjects(deleted);
|
|
98
|
+
}).then(function () {
|
|
99
|
+
return _this.applyDiff({
|
|
100
|
+
deleted: deleted
|
|
101
|
+
}, type);
|
|
107
102
|
});
|
|
108
|
-
return {
|
|
109
|
-
inserted: newObjects,
|
|
110
|
-
updated: edited,
|
|
111
|
-
deleted: deleted
|
|
112
|
-
};
|
|
113
103
|
});
|
|
114
104
|
});
|
|
115
105
|
|
|
116
|
-
_defineProperty(_assertThisInitialized(_this), "save", function () {
|
|
117
|
-
return Promise.all(Object.keys(_this.models).map(_this._saveType));
|
|
118
|
-
});
|
|
119
|
-
|
|
120
106
|
_defineProperty(_assertThisInitialized(_this), "delayedSave", function () {
|
|
121
107
|
if (_this.options.autoSave) {
|
|
122
|
-
if (_this.
|
|
123
|
-
clearTimeout(_this.
|
|
108
|
+
if (_this._delayedSaveTimer) {
|
|
109
|
+
clearTimeout(_this._delayedSaveTimer);
|
|
124
110
|
}
|
|
125
111
|
|
|
126
|
-
_this.
|
|
112
|
+
_this._delayedSaveTimer = setTimeout(_this.save, _this.options.saveDelay);
|
|
127
113
|
}
|
|
128
|
-
|
|
129
|
-
return Promise.resolve();
|
|
130
114
|
});
|
|
131
115
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
});
|
|
116
|
+
_this.axios = options.axios || _axios["default"];
|
|
117
|
+
_this._busy = false;
|
|
118
|
+
_this._delayedSaveTimer = null;
|
|
137
119
|
|
|
138
120
|
if (typeof _this.options.autoSave === "number") {
|
|
139
|
-
setInterval(
|
|
121
|
+
setInterval(function () {
|
|
122
|
+
if (!_this._busy) {
|
|
123
|
+
_this.delayedSave();
|
|
124
|
+
}
|
|
125
|
+
}, _this.options.autoSave);
|
|
140
126
|
}
|
|
141
127
|
|
|
142
128
|
return _this;
|
|
143
129
|
}
|
|
144
130
|
|
|
145
|
-
|
|
131
|
+
_createClass(PersistentStore, [{
|
|
132
|
+
key: "addModel",
|
|
133
|
+
value: function addModel(model) {
|
|
134
|
+
var _this2 = this;
|
|
135
|
+
|
|
136
|
+
this._busy = true;
|
|
137
|
+
|
|
138
|
+
_get(_getPrototypeOf(PersistentStore.prototype), "addModel", this).call(this, model).then(function () {
|
|
139
|
+
_this2._busy = false;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}, {
|
|
143
|
+
key: "insert",
|
|
144
|
+
value: function insert(type, objects) {
|
|
145
|
+
var _this3 = this;
|
|
146
|
+
|
|
147
|
+
return _get(_getPrototypeOf(PersistentStore.prototype), "insert", this).call(this, type, objects).then(function (data) {
|
|
148
|
+
_this3.delayedSave();
|
|
149
|
+
|
|
150
|
+
return data;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
key: "delete",
|
|
155
|
+
value: function _delete(typeOrObjects, filterFunction) {
|
|
156
|
+
var _this4 = this;
|
|
157
|
+
|
|
158
|
+
return _get(_getPrototypeOf(PersistentStore.prototype), "delete", this).call(this, typeOrObjects, filterFunction).then(function (data) {
|
|
159
|
+
_this4.delayedSave();
|
|
160
|
+
|
|
161
|
+
return data;
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}, {
|
|
165
|
+
key: "update",
|
|
166
|
+
value: function update(objects) {
|
|
167
|
+
var _this5 = this;
|
|
168
|
+
|
|
169
|
+
return _get(_getPrototypeOf(PersistentStore.prototype), "update", this).call(this, objects).then(function (data) {
|
|
170
|
+
_this5.delayedSave();
|
|
171
|
+
|
|
172
|
+
return data;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}]);
|
|
176
|
+
|
|
177
|
+
return PersistentStore;
|
|
146
178
|
}(_Store2["default"]);
|
|
147
179
|
|
|
148
180
|
exports["default"] = PersistentStore;
|