dataflux 1.14.4 → 1.14.6
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/BasicObj.js +23 -38
- package/dist/Model.js +175 -250
- package/dist/Obj.js +28 -33
- package/dist/ObserverStore.js +96 -121
- package/dist/PersistentStore.js +9 -10
- package/dist/PubSub.js +1 -1
- package/dist/ReactStore.js +35 -41
- package/dist/Store.js +58 -77
- package/dist/SubObj.js +26 -37
- package/dist/dataflux.min.js +1 -1
- package/dist/dataflux.min.js.map +1 -1
- package/dist/modelHooksUtils.js +1 -1
- package/package.json +10 -10
package/dist/Obj.js
CHANGED
|
@@ -14,23 +14,21 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
14
14
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
15
15
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
16
16
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
17
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
18
17
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
18
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
19
19
|
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); }
|
|
20
20
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
21
21
|
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } 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); }
|
|
22
22
|
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
23
23
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
24
24
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
25
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
26
26
|
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); }
|
|
27
27
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
28
28
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
29
|
-
function _classPrivateFieldSet(
|
|
30
|
-
function
|
|
31
|
-
function
|
|
32
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
33
|
-
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } /*
|
|
29
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
30
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
31
|
+
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"); } /*
|
|
34
32
|
* MIT License
|
|
35
33
|
*
|
|
36
34
|
* Copyright (c) 2022 Massimo Candela <https://massimocandela.com>
|
|
@@ -55,60 +53,57 @@ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) {
|
|
|
55
53
|
*/
|
|
56
54
|
var _loaded = /*#__PURE__*/new WeakMap();
|
|
57
55
|
var Obj = exports["default"] = /*#__PURE__*/function (_BasicObj) {
|
|
58
|
-
_inherits(Obj, _BasicObj);
|
|
59
56
|
function Obj(values, _model) {
|
|
60
|
-
var
|
|
57
|
+
var _this;
|
|
61
58
|
_classCallCheck(this, Obj);
|
|
62
59
|
_this = _callSuper(this, Obj, [values, _model]);
|
|
63
|
-
_classPrivateFieldInitSpec(
|
|
64
|
-
|
|
65
|
-
value: false
|
|
66
|
-
});
|
|
67
|
-
_defineProperty(_assertThisInitialized(_this), "set", function (attribute, value, hidden) {
|
|
60
|
+
_classPrivateFieldInitSpec(_this, _loaded, false);
|
|
61
|
+
_defineProperty(_this, "set", function (attribute, value, hidden) {
|
|
68
62
|
if (Array.isArray(value) && _this.getModel().options.deep) {
|
|
69
63
|
value = value.map(function (i) {
|
|
70
64
|
if (["boolean", "string", "number"].includes(_typeof(i))) {
|
|
71
65
|
return i;
|
|
72
66
|
} else {
|
|
73
|
-
return i !== null && i !== void 0 && i.getId ? i : new _SubObj["default"](
|
|
67
|
+
return i !== null && i !== void 0 && i.getId ? i : new _SubObj["default"](_this, "property", i, _this.getModel());
|
|
74
68
|
}
|
|
75
69
|
});
|
|
76
70
|
}
|
|
77
|
-
return _get((
|
|
71
|
+
return _get((_this, _getPrototypeOf(Obj.prototype)), "set", _this).call(_this, attribute, value, hidden);
|
|
78
72
|
});
|
|
79
|
-
_defineProperty(
|
|
80
|
-
if (_classPrivateFieldGet(
|
|
81
|
-
return Promise.resolve(
|
|
73
|
+
_defineProperty(_this, "load", function () {
|
|
74
|
+
if (_classPrivateFieldGet(_loaded, _this)) {
|
|
75
|
+
return Promise.resolve(_this);
|
|
82
76
|
} else {
|
|
83
77
|
var model = _this.getModel();
|
|
84
|
-
return model.load(
|
|
85
|
-
_classPrivateFieldSet(
|
|
86
|
-
return model.getStore().update([
|
|
78
|
+
return model.load(_this).then(function () {
|
|
79
|
+
_classPrivateFieldSet(_loaded, _this, true);
|
|
80
|
+
return model.getStore().update([_this], true); // Propagate update
|
|
87
81
|
}).then(function () {
|
|
88
|
-
return
|
|
82
|
+
return _this;
|
|
89
83
|
}); // return always this
|
|
90
84
|
}
|
|
91
85
|
});
|
|
92
|
-
_defineProperty(
|
|
86
|
+
_defineProperty(_this, "getFingerprint", function () {
|
|
93
87
|
return (0, _fingerprint["default"])(_this.toJSON());
|
|
94
88
|
});
|
|
95
|
-
_defineProperty(
|
|
96
|
-
return _this.getModel().getRelation(
|
|
89
|
+
_defineProperty(_this, "getRelation", function (type, filterFunction) {
|
|
90
|
+
return _this.getModel().getRelation(_this, type, filterFunction);
|
|
97
91
|
});
|
|
98
|
-
_defineProperty(
|
|
99
|
-
return _this.getModel().getStore().save([
|
|
92
|
+
_defineProperty(_this, "save", function () {
|
|
93
|
+
return _this.getModel().getStore().save([_this]);
|
|
100
94
|
});
|
|
101
|
-
_defineProperty(
|
|
102
|
-
return _this.getModel().getStore()["delete"]([
|
|
95
|
+
_defineProperty(_this, "destroy", function () {
|
|
96
|
+
return _this.getModel().getStore()["delete"]([_this]);
|
|
103
97
|
});
|
|
104
|
-
_defineProperty(
|
|
105
|
-
return _this.getModel().getStore().update([
|
|
98
|
+
_defineProperty(_this, "update", function () {
|
|
99
|
+
return _this.getModel().getStore().update([_this]);
|
|
106
100
|
});
|
|
107
|
-
(0, _BasicObj2.setValues)(values, _model, _SubObj["default"],
|
|
101
|
+
(0, _BasicObj2.setValues)(values, _model, _SubObj["default"], _this, _this);
|
|
108
102
|
_this.getModel = function () {
|
|
109
103
|
return _model;
|
|
110
104
|
};
|
|
111
105
|
return _this;
|
|
112
106
|
}
|
|
107
|
+
_inherits(Obj, _BasicObj);
|
|
113
108
|
return _createClass(Obj);
|
|
114
109
|
}(_BasicObj2.BasicObj);
|
package/dist/ObserverStore.js
CHANGED
|
@@ -21,8 +21,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
21
21
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
22
22
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
23
23
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
24
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
25
24
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
25
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
26
26
|
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } 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); }
|
|
27
27
|
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
28
28
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
@@ -30,16 +30,13 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
|
|
30
30
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
31
31
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
32
32
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
33
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
33
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
34
34
|
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); }
|
|
35
35
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
36
36
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
37
|
-
function
|
|
38
|
-
function
|
|
39
|
-
function
|
|
40
|
-
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
41
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
42
|
-
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } /*
|
|
37
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
38
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
39
|
+
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"); } /*
|
|
43
40
|
* MIT License
|
|
44
41
|
*
|
|
45
42
|
* Copyright (c) 2022 Massimo Candela <https://massimocandela.com>
|
|
@@ -69,23 +66,16 @@ var _propagateChange = /*#__PURE__*/new WeakMap();
|
|
|
69
66
|
var _appendIfNotExistent = /*#__PURE__*/new WeakMap();
|
|
70
67
|
var _subscribeToObjects = /*#__PURE__*/new WeakMap();
|
|
71
68
|
var _merge = /*#__PURE__*/new WeakMap();
|
|
72
|
-
var
|
|
69
|
+
var _ObserverStore_brand = /*#__PURE__*/new WeakSet();
|
|
73
70
|
var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
74
|
-
_inherits(ObserverStore, _PersistentStore);
|
|
75
71
|
function ObserverStore(options) {
|
|
76
72
|
var _this;
|
|
77
73
|
_classCallCheck(this, ObserverStore);
|
|
78
74
|
_this = _callSuper(this, ObserverStore, [options]);
|
|
79
|
-
_classPrivateMethodInitSpec(
|
|
80
|
-
_classPrivateFieldInitSpec(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _unsubPromises, {
|
|
85
|
-
writable: true,
|
|
86
|
-
value: []
|
|
87
|
-
});
|
|
88
|
-
_defineProperty(_assertThisInitialized(_this), "multipleSubscribe", function (subscriptions, callback) {
|
|
75
|
+
_classPrivateMethodInitSpec(_this, _ObserverStore_brand);
|
|
76
|
+
_classPrivateFieldInitSpec(_this, _queryPromises, []);
|
|
77
|
+
_classPrivateFieldInitSpec(_this, _unsubPromises, []);
|
|
78
|
+
_defineProperty(_this, "multipleSubscribe", function (subscriptions, callback) {
|
|
89
79
|
var dataPayload = {};
|
|
90
80
|
var subKey = (0, _uuid.v4)();
|
|
91
81
|
var areAllDone = function areAllDone() {
|
|
@@ -113,23 +103,23 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
113
103
|
});
|
|
114
104
|
return subKey;
|
|
115
105
|
});
|
|
116
|
-
_defineProperty(
|
|
106
|
+
_defineProperty(_this, "subscribe", function (type, callback, filterFunction) {
|
|
117
107
|
var _this$_subscribed, _this$_subscribed$typ;
|
|
118
108
|
var subKey = (0, _uuid.v4)();
|
|
119
109
|
(_this$_subscribed$typ = (_this$_subscribed = _this._subscribed)[type]) !== null && _this$_subscribed$typ !== void 0 ? _this$_subscribed$typ : _this$_subscribed[type] = {};
|
|
120
110
|
var prom = _this.find(type, filterFunction).then(function (data) {
|
|
121
|
-
_classPrivateFieldGet(
|
|
111
|
+
_classPrivateFieldGet(_subscribeToObjects, _this).call(_this, type, data, {
|
|
122
112
|
callback: callback,
|
|
123
113
|
filterFunction: filterFunction,
|
|
124
114
|
subKey: subKey
|
|
125
115
|
});
|
|
126
116
|
callback(data);
|
|
127
117
|
});
|
|
128
|
-
_classPrivateFieldGet(
|
|
118
|
+
_classPrivateFieldGet(_queryPromises, _this).push(prom);
|
|
129
119
|
return subKey;
|
|
130
120
|
});
|
|
131
|
-
_defineProperty(
|
|
132
|
-
_classPrivateFieldSet(
|
|
121
|
+
_defineProperty(_this, "unsubscribe", function (key) {
|
|
122
|
+
_classPrivateFieldSet(_unsubPromises, _this, (_classPrivateFieldGet(_queryPromises, _this).length ? Promise.all(_classPrivateFieldGet(_queryPromises, _this)) : Promise.resolve()).then(function () {
|
|
133
123
|
if (_this._multipleSubscribed[key]) {
|
|
134
124
|
var _iterator = _createForOfIteratorHelper(_this._multipleSubscribed[key]),
|
|
135
125
|
_step;
|
|
@@ -163,99 +153,87 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
163
153
|
}
|
|
164
154
|
}));
|
|
165
155
|
});
|
|
166
|
-
_classPrivateFieldInitSpec(
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var sub = _step3.value;
|
|
184
|
-
(_out$_sub$subKey = out[_sub$subKey = sub.subKey]) !== null && _out$_sub$subKey !== void 0 ? _out$_sub$subKey : out[_sub$subKey] = sub;
|
|
185
|
-
}
|
|
186
|
-
} catch (err) {
|
|
187
|
-
_iterator3.e(err);
|
|
188
|
-
} finally {
|
|
189
|
-
_iterator3.f();
|
|
156
|
+
_classPrivateFieldInitSpec(_this, _getUniqueSubs, function (objects, type) {
|
|
157
|
+
var out = {};
|
|
158
|
+
var _iterator2 = _createForOfIteratorHelper(objects),
|
|
159
|
+
_step2;
|
|
160
|
+
try {
|
|
161
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
162
|
+
var object = _step2.value;
|
|
163
|
+
var objectId = object.getId();
|
|
164
|
+
var typeChannel = _this._subscribed[type] || {};
|
|
165
|
+
var subscribedToObject = typeChannel[objectId] || [];
|
|
166
|
+
var _iterator3 = _createForOfIteratorHelper(subscribedToObject),
|
|
167
|
+
_step3;
|
|
168
|
+
try {
|
|
169
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
170
|
+
var _sub$subKey, _out$_sub$subKey;
|
|
171
|
+
var sub = _step3.value;
|
|
172
|
+
(_out$_sub$subKey = out[_sub$subKey = sub.subKey]) !== null && _out$_sub$subKey !== void 0 ? _out$_sub$subKey : out[_sub$subKey] = sub;
|
|
190
173
|
}
|
|
174
|
+
} catch (err) {
|
|
175
|
+
_iterator3.e(err);
|
|
176
|
+
} finally {
|
|
177
|
+
_iterator3.f();
|
|
191
178
|
}
|
|
192
|
-
} catch (err) {
|
|
193
|
-
_iterator2.e(err);
|
|
194
|
-
} finally {
|
|
195
|
-
_iterator2.f();
|
|
196
179
|
}
|
|
197
|
-
|
|
180
|
+
} catch (err) {
|
|
181
|
+
_iterator2.e(err);
|
|
182
|
+
} finally {
|
|
183
|
+
_iterator2.f();
|
|
198
184
|
}
|
|
185
|
+
return Object.values(out);
|
|
199
186
|
});
|
|
200
|
-
_classPrivateFieldInitSpec(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return _this.find(type, filterFunction).then(callback);
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
return objects;
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
_classPrivateFieldInitSpec(_assertThisInitialized(_this), _appendIfNotExistent, {
|
|
219
|
-
writable: true,
|
|
220
|
-
value: function value(arr, item) {
|
|
221
|
-
if (Object.values(arr).filter(function (_ref4) {
|
|
222
|
-
var subKey = _ref4.subKey;
|
|
223
|
-
return item.subKey === subKey;
|
|
224
|
-
}).length === 0) {
|
|
225
|
-
arr.push(item);
|
|
187
|
+
_classPrivateFieldInitSpec(_this, _propagateChange, function () {
|
|
188
|
+
var objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
189
|
+
return (_classPrivateFieldGet(_unsubPromises, _this).length ? Promise.all(_classPrivateFieldGet(_unsubPromises, _this)) : Promise.resolve()).then(function () {
|
|
190
|
+
if (objects.length) {
|
|
191
|
+
var type = objects[0].getModel().getType();
|
|
192
|
+
var uniqueSubs = _classPrivateFieldGet(_getUniqueSubs, _this).call(_this, objects, type);
|
|
193
|
+
(0, _batchPromises["default"])(10, uniqueSubs, function (_ref3) {
|
|
194
|
+
var callback = _ref3.callback,
|
|
195
|
+
filterFunction = _ref3.filterFunction;
|
|
196
|
+
return _this.find(type, filterFunction).then(callback);
|
|
197
|
+
});
|
|
226
198
|
}
|
|
199
|
+
return objects;
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
_classPrivateFieldInitSpec(_this, _appendIfNotExistent, function (arr, item) {
|
|
203
|
+
if (Object.values(arr).filter(function (_ref4) {
|
|
204
|
+
var subKey = _ref4.subKey;
|
|
205
|
+
return item.subKey === subKey;
|
|
206
|
+
}).length === 0) {
|
|
207
|
+
arr.push(item);
|
|
227
208
|
}
|
|
228
209
|
});
|
|
229
|
-
_classPrivateFieldInitSpec(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
(_this$_subscribed$typ5 = (_this$_subscribed$typ4 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ5 !== void 0 ? _this$_subscribed$typ5 : _this$_subscribed$typ4[id] = [];
|
|
241
|
-
_classPrivateFieldGet(_assertThisInitialized(_this), _appendIfNotExistent).call(_assertThisInitialized(_this), _this._subscribed[type][id], item);
|
|
242
|
-
}
|
|
243
|
-
} catch (err) {
|
|
244
|
-
_iterator4.e(err);
|
|
245
|
-
} finally {
|
|
246
|
-
_iterator4.f();
|
|
210
|
+
_classPrivateFieldInitSpec(_this, _subscribeToObjects, function (type, objectsToSubscribe, item) {
|
|
211
|
+
var _this$_subscribed$typ2, _, _this$_subscribed$typ3;
|
|
212
|
+
var _iterator4 = _createForOfIteratorHelper(objectsToSubscribe),
|
|
213
|
+
_step4;
|
|
214
|
+
try {
|
|
215
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
216
|
+
var _this$_subscribed$typ4, _this$_subscribed$typ5;
|
|
217
|
+
var object = _step4.value;
|
|
218
|
+
var id = object.getId();
|
|
219
|
+
(_this$_subscribed$typ5 = (_this$_subscribed$typ4 = _this._subscribed[type])[id]) !== null && _this$_subscribed$typ5 !== void 0 ? _this$_subscribed$typ5 : _this$_subscribed$typ4[id] = [];
|
|
220
|
+
_classPrivateFieldGet(_appendIfNotExistent, _this).call(_this, _this._subscribed[type][id], item);
|
|
247
221
|
}
|
|
248
|
-
|
|
249
|
-
|
|
222
|
+
} catch (err) {
|
|
223
|
+
_iterator4.e(err);
|
|
224
|
+
} finally {
|
|
225
|
+
_iterator4.f();
|
|
250
226
|
}
|
|
227
|
+
(_this$_subscribed$typ3 = (_this$_subscribed$typ2 = _this._subscribed[type])[_ = "*"]) !== null && _this$_subscribed$typ3 !== void 0 ? _this$_subscribed$typ3 : _this$_subscribed$typ2[_] = [];
|
|
228
|
+
_classPrivateFieldGet(_appendIfNotExistent, _this).call(_this, _this._subscribed[type]["*"], item);
|
|
251
229
|
});
|
|
252
|
-
_defineProperty(
|
|
230
|
+
_defineProperty(_this, "reset", function (type) {
|
|
253
231
|
return _this._refresh(type, true);
|
|
254
232
|
});
|
|
255
|
-
_defineProperty(
|
|
233
|
+
_defineProperty(_this, "refresh", function (type) {
|
|
256
234
|
return _this._refresh(type, false);
|
|
257
235
|
});
|
|
258
|
-
_defineProperty(
|
|
236
|
+
_defineProperty(_this, "_refresh", function (type, force) {
|
|
259
237
|
var refreshByType = function refreshByType(type) {
|
|
260
238
|
_this.pubSub.publish("refresh", {
|
|
261
239
|
status: "start",
|
|
@@ -267,7 +245,7 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
267
245
|
updated = _ref6[1],
|
|
268
246
|
deleted = _ref6[2];
|
|
269
247
|
var item = _this.models[type];
|
|
270
|
-
return Promise.all([
|
|
248
|
+
return Promise.all([_assertClassBrand(_ObserverStore_brand, _this, _propagateInsertChange).call(_this, type, inserted), _classPrivateFieldGet(_propagateChange, _this).call(_this, updated), _classPrivateFieldGet(_propagateChange, _this).call(_this, deleted)]).then(function () {
|
|
271
249
|
_this.pubSub.publish("refresh", {
|
|
272
250
|
status: "end",
|
|
273
251
|
model: type
|
|
@@ -282,14 +260,11 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
282
260
|
return Promise.all(Object.keys(_this.models).map(refreshByType));
|
|
283
261
|
}
|
|
284
262
|
});
|
|
285
|
-
_classPrivateFieldInitSpec(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
for (var key in newObject) {
|
|
289
|
-
originalObject[key] = newObject[key];
|
|
290
|
-
}
|
|
291
|
-
originalObject.update();
|
|
263
|
+
_classPrivateFieldInitSpec(_this, _merge, function (originalObject, newObject) {
|
|
264
|
+
for (var key in newObject) {
|
|
265
|
+
originalObject[key] = newObject[key];
|
|
292
266
|
}
|
|
267
|
+
originalObject.update();
|
|
293
268
|
});
|
|
294
269
|
_this._subscribed = {};
|
|
295
270
|
_this._multipleSubscribed = {};
|
|
@@ -298,13 +273,14 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
298
273
|
}
|
|
299
274
|
return _this;
|
|
300
275
|
}
|
|
301
|
-
|
|
276
|
+
_inherits(ObserverStore, _PersistentStore);
|
|
277
|
+
return _createClass(ObserverStore, [{
|
|
302
278
|
key: "update",
|
|
303
279
|
value: function update(objects, skipSave) {
|
|
304
280
|
if (!skipSave) {
|
|
305
|
-
_classPrivateFieldGet(
|
|
281
|
+
_classPrivateFieldGet(_propagateChange, this).call(this, objects);
|
|
306
282
|
}
|
|
307
|
-
return _get(_getPrototypeOf(ObserverStore.prototype), "update", this).call(this, objects, skipSave).then(_classPrivateFieldGet(
|
|
283
|
+
return _get(_getPrototypeOf(ObserverStore.prototype), "update", this).call(this, objects, skipSave).then(_classPrivateFieldGet(_propagateChange, this));
|
|
308
284
|
}
|
|
309
285
|
}, {
|
|
310
286
|
key: "insert",
|
|
@@ -312,7 +288,7 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
312
288
|
var _this2 = this;
|
|
313
289
|
objects = Array.isArray(objects) ? objects : [objects];
|
|
314
290
|
return _get(_getPrototypeOf(ObserverStore.prototype), "insert", this).call(this, type, objects).then(function (objects) {
|
|
315
|
-
|
|
291
|
+
_assertClassBrand(_ObserverStore_brand, _this2, _propagateInsertChange).call(_this2, type, objects);
|
|
316
292
|
return objects;
|
|
317
293
|
});
|
|
318
294
|
}
|
|
@@ -322,21 +298,20 @@ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
|
|
|
322
298
|
var _this3 = this;
|
|
323
299
|
objects = Array.isArray(objects) ? objects : [objects];
|
|
324
300
|
return _get(_getPrototypeOf(ObserverStore.prototype), "mock", this).call(this, type, objects).then(function (objects) {
|
|
325
|
-
|
|
301
|
+
_assertClassBrand(_ObserverStore_brand, _this3, _propagateInsertChange).call(_this3, type, objects);
|
|
326
302
|
return objects;
|
|
327
303
|
});
|
|
328
304
|
}
|
|
329
305
|
}, {
|
|
330
306
|
key: "delete",
|
|
331
307
|
value: function _delete(typeOrObjects, filterFunction) {
|
|
332
|
-
return _get(_getPrototypeOf(ObserverStore.prototype), "delete", this).call(this, typeOrObjects, filterFunction).then(_classPrivateFieldGet(
|
|
308
|
+
return _get(_getPrototypeOf(ObserverStore.prototype), "delete", this).call(this, typeOrObjects, filterFunction).then(_classPrivateFieldGet(_propagateChange, this));
|
|
333
309
|
}
|
|
334
310
|
}]);
|
|
335
|
-
return ObserverStore;
|
|
336
311
|
}(_PersistentStore2["default"]);
|
|
337
|
-
function
|
|
312
|
+
function _propagateInsertChange(type, newObjects) {
|
|
338
313
|
var _this4 = this;
|
|
339
|
-
return (_classPrivateFieldGet(
|
|
314
|
+
return (_classPrivateFieldGet(_unsubPromises, this).length ? Promise.all(_classPrivateFieldGet(_unsubPromises, this)) : Promise.resolve()).then(function () {
|
|
340
315
|
if (_this4._subscribed[type]) {
|
|
341
316
|
var uniqueSubs = {};
|
|
342
317
|
var objects = Object.values(_this4._subscribed[type]);
|
|
@@ -367,7 +342,7 @@ function _propagateInsertChange2(type, newObjects) {
|
|
|
367
342
|
// Check if the new objects matter
|
|
368
343
|
|
|
369
344
|
return _this4.find(type, filterFunction).then(function (data) {
|
|
370
|
-
_classPrivateFieldGet(
|
|
345
|
+
_classPrivateFieldGet(_subscribeToObjects, _this4).call(_this4, type, objectsToSubscribe, {
|
|
371
346
|
callback: callback,
|
|
372
347
|
filterFunction: filterFunction,
|
|
373
348
|
subKey: subKey
|
package/dist/PersistentStore.js
CHANGED
|
@@ -15,15 +15,15 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
15
15
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
16
16
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
17
17
|
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
18
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
19
18
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
19
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
20
20
|
function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } 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
21
|
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
22
22
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
23
|
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); }
|
|
24
24
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
25
25
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
26
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
26
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
27
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
28
|
* MIT License
|
|
29
29
|
*
|
|
@@ -48,12 +48,11 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
48
48
|
* SOFTWARE.
|
|
49
49
|
*/
|
|
50
50
|
var PersistentStore = exports["default"] = /*#__PURE__*/function (_Store) {
|
|
51
|
-
_inherits(PersistentStore, _Store);
|
|
52
51
|
function PersistentStore(options) {
|
|
53
52
|
var _this;
|
|
54
53
|
_classCallCheck(this, PersistentStore);
|
|
55
54
|
_this = _callSuper(this, PersistentStore, [options]);
|
|
56
|
-
_defineProperty(
|
|
55
|
+
_defineProperty(_this, "whenSaved", function (type) {
|
|
57
56
|
return _this.getDiff(type).then(function (_ref) {
|
|
58
57
|
var inserted = _ref.inserted,
|
|
59
58
|
updated = _ref.updated,
|
|
@@ -71,7 +70,7 @@ var PersistentStore = exports["default"] = /*#__PURE__*/function (_Store) {
|
|
|
71
70
|
}
|
|
72
71
|
});
|
|
73
72
|
});
|
|
74
|
-
_defineProperty(
|
|
73
|
+
_defineProperty(_this, "save", function () {
|
|
75
74
|
_this._busy = true;
|
|
76
75
|
_this.pubSub.publish("save", "start");
|
|
77
76
|
if (_this._delayedSaveTimer) {
|
|
@@ -90,7 +89,7 @@ var PersistentStore = exports["default"] = /*#__PURE__*/function (_Store) {
|
|
|
90
89
|
return Promise.reject(error);
|
|
91
90
|
});
|
|
92
91
|
});
|
|
93
|
-
_defineProperty(
|
|
92
|
+
_defineProperty(_this, "_saveDiff", function (type, _ref2) {
|
|
94
93
|
var inserted = _ref2.inserted,
|
|
95
94
|
updated = _ref2.updated,
|
|
96
95
|
deleted = _ref2.deleted;
|
|
@@ -135,12 +134,12 @@ var PersistentStore = exports["default"] = /*#__PURE__*/function (_Store) {
|
|
|
135
134
|
}, type);
|
|
136
135
|
});
|
|
137
136
|
});
|
|
138
|
-
_defineProperty(
|
|
137
|
+
_defineProperty(_this, "_saveByType", function (type, ifLoaded) {
|
|
139
138
|
return _this.getDiff(type, ifLoaded).then(function (diff) {
|
|
140
139
|
return _this._saveDiff(type, diff);
|
|
141
140
|
});
|
|
142
141
|
});
|
|
143
|
-
_defineProperty(
|
|
142
|
+
_defineProperty(_this, "delayedSave", function () {
|
|
144
143
|
return new Promise(function (resolve, reject) {
|
|
145
144
|
if (_this.options.autoSave) {
|
|
146
145
|
if (_this._delayedSaveTimer) {
|
|
@@ -173,7 +172,8 @@ var PersistentStore = exports["default"] = /*#__PURE__*/function (_Store) {
|
|
|
173
172
|
}
|
|
174
173
|
return _this;
|
|
175
174
|
}
|
|
176
|
-
|
|
175
|
+
_inherits(PersistentStore, _Store);
|
|
176
|
+
return _createClass(PersistentStore, [{
|
|
177
177
|
key: "addModel",
|
|
178
178
|
value: function addModel(model) {
|
|
179
179
|
var _this2 = this;
|
|
@@ -235,5 +235,4 @@ var PersistentStore = exports["default"] = /*#__PURE__*/function (_Store) {
|
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
237
|
}]);
|
|
238
|
-
return PersistentStore;
|
|
239
238
|
}(_Store2["default"]);
|
package/dist/PubSub.js
CHANGED
|
@@ -12,7 +12,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
12
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
13
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
14
14
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
16
16
|
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); }
|
|
17
17
|
/*
|
|
18
18
|
* MIT License
|