dataflux 1.0.4 → 1.2.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 +270 -127
- package/dist/Model.js +241 -57
- package/dist/ObserverStore.js +178 -131
- package/dist/PersistentStore.js +104 -75
- package/dist/PubSub.js +59 -0
- package/dist/ReactStore.js +22 -2
- package/dist/Store.js +295 -151
- package/dist/StoreObject.js +33 -0
- package/dist/fingerprint.js +8 -12
- package/dist/modelHooksUtils.js +61 -19
- package/package.json +6 -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
|
@@ -11,17 +11,15 @@ var _Store2 = _interopRequireDefault(require("./Store"));
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
13
13
|
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
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); }
|
|
17
|
-
|
|
18
|
-
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; }
|
|
14
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
19
15
|
|
|
20
16
|
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
17
|
|
|
22
18
|
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
19
|
|
|
24
|
-
function
|
|
20
|
+
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); }
|
|
21
|
+
|
|
22
|
+
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
25
23
|
|
|
26
24
|
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
25
|
|
|
@@ -51,98 +49,129 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
|
|
|
51
49
|
|
|
52
50
|
_this = _super.call(this, options);
|
|
53
51
|
|
|
54
|
-
_defineProperty(_assertThisInitialized(_this), "
|
|
55
|
-
|
|
52
|
+
_defineProperty(_assertThisInitialized(_this), "save", function () {
|
|
53
|
+
_this._busy = true;
|
|
54
|
+
|
|
55
|
+
_this.pubSub.publish("save", "start");
|
|
56
|
+
|
|
57
|
+
return Promise.all(Object.keys(_this.models).map(_this._saveByType)).then(function (data) {
|
|
58
|
+
_this._busy = false;
|
|
59
|
+
|
|
60
|
+
_this.pubSub.publish("save", "end");
|
|
61
|
+
|
|
62
|
+
return data;
|
|
63
|
+
})["catch"](function (error) {
|
|
64
|
+
_this._busy = false;
|
|
65
|
+
|
|
66
|
+
_this.pubSub.publish("save", "end");
|
|
67
|
+
|
|
68
|
+
_this.pubSub.publish("error", error);
|
|
69
|
+
|
|
70
|
+
return Promise.reject(error);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
_defineProperty(_assertThisInitialized(_this), "_saveByType", function (type) {
|
|
75
|
+
return _this.getDiff(type).then(function (_ref) {
|
|
56
76
|
var inserted = _ref.inserted,
|
|
57
77
|
updated = _ref.updated,
|
|
58
78
|
deleted = _ref.deleted;
|
|
59
|
-
|
|
60
|
-
|
|
79
|
+
var model = _this.models[type].model; // Operations order:
|
|
80
|
+
// 1) insert
|
|
81
|
+
// 2) update
|
|
82
|
+
// 3) delete
|
|
83
|
+
|
|
84
|
+
return model.insertObjects(inserted).then(function () {
|
|
85
|
+
return _this.applyDiff({
|
|
86
|
+
inserted: inserted
|
|
87
|
+
}, type);
|
|
61
88
|
}).then(function () {
|
|
62
|
-
return
|
|
89
|
+
return model.updateObjects(updated);
|
|
63
90
|
}).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";
|
|
91
|
+
return _this.applyDiff({
|
|
92
|
+
updated: updated
|
|
93
|
+
}, type);
|
|
94
|
+
}).then(function () {
|
|
95
|
+
return model.deleteObjects(deleted);
|
|
96
|
+
}).then(function () {
|
|
97
|
+
return _this.applyDiff({
|
|
98
|
+
deleted: deleted
|
|
99
|
+
}, type);
|
|
107
100
|
});
|
|
108
|
-
return {
|
|
109
|
-
inserted: newObjects,
|
|
110
|
-
updated: edited,
|
|
111
|
-
deleted: deleted
|
|
112
|
-
};
|
|
113
101
|
});
|
|
114
102
|
});
|
|
115
103
|
|
|
116
|
-
_defineProperty(_assertThisInitialized(_this), "save", function () {
|
|
117
|
-
return Promise.all(Object.keys(_this.models).map(_this._saveType));
|
|
118
|
-
});
|
|
119
|
-
|
|
120
104
|
_defineProperty(_assertThisInitialized(_this), "delayedSave", function () {
|
|
121
105
|
if (_this.options.autoSave) {
|
|
122
|
-
if (_this.
|
|
123
|
-
clearTimeout(_this.
|
|
106
|
+
if (_this._delayedSaveTimer) {
|
|
107
|
+
clearTimeout(_this._delayedSaveTimer);
|
|
124
108
|
}
|
|
125
109
|
|
|
126
|
-
_this.
|
|
110
|
+
_this._delayedSaveTimer = setTimeout(_this.save, _this.options.saveDelay);
|
|
127
111
|
}
|
|
128
|
-
|
|
129
|
-
return Promise.resolve();
|
|
130
112
|
});
|
|
131
113
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
_this.delayedSave();
|
|
135
|
-
}
|
|
136
|
-
});
|
|
114
|
+
_this._busy = false;
|
|
115
|
+
_this._delayedSaveTimer = null;
|
|
137
116
|
|
|
138
117
|
if (typeof _this.options.autoSave === "number") {
|
|
139
|
-
setInterval(
|
|
118
|
+
setInterval(function () {
|
|
119
|
+
if (!_this._busy) {
|
|
120
|
+
_this.delayedSave();
|
|
121
|
+
}
|
|
122
|
+
}, _this.options.autoSave);
|
|
140
123
|
}
|
|
141
124
|
|
|
142
125
|
return _this;
|
|
143
126
|
}
|
|
144
127
|
|
|
145
|
-
|
|
128
|
+
_createClass(PersistentStore, [{
|
|
129
|
+
key: "addModel",
|
|
130
|
+
value: function addModel(model) {
|
|
131
|
+
var _this2 = this;
|
|
132
|
+
|
|
133
|
+
this._busy = true;
|
|
134
|
+
|
|
135
|
+
_get(_getPrototypeOf(PersistentStore.prototype), "addModel", this).call(this, model).then(function () {
|
|
136
|
+
_this2._busy = false;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}, {
|
|
140
|
+
key: "insert",
|
|
141
|
+
value: function insert(type, objects) {
|
|
142
|
+
var _this3 = this;
|
|
143
|
+
|
|
144
|
+
return _get(_getPrototypeOf(PersistentStore.prototype), "insert", this).call(this, type, objects).then(function (data) {
|
|
145
|
+
_this3.delayedSave();
|
|
146
|
+
|
|
147
|
+
return data;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}, {
|
|
151
|
+
key: "delete",
|
|
152
|
+
value: function _delete(typeOrObjects, filterFunction) {
|
|
153
|
+
var _this4 = this;
|
|
154
|
+
|
|
155
|
+
return _get(_getPrototypeOf(PersistentStore.prototype), "delete", this).call(this, typeOrObjects, filterFunction).then(function (data) {
|
|
156
|
+
_this4.delayedSave();
|
|
157
|
+
|
|
158
|
+
return data;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}, {
|
|
162
|
+
key: "update",
|
|
163
|
+
value: function update(objects) {
|
|
164
|
+
var _this5 = this;
|
|
165
|
+
|
|
166
|
+
return _get(_getPrototypeOf(PersistentStore.prototype), "update", this).call(this, objects).then(function (data) {
|
|
167
|
+
_this5.delayedSave();
|
|
168
|
+
|
|
169
|
+
return data;
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}]);
|
|
173
|
+
|
|
174
|
+
return PersistentStore;
|
|
146
175
|
}(_Store2["default"]);
|
|
147
176
|
|
|
148
177
|
exports["default"] = PersistentStore;
|