dataflux 1.14.3 → 1.14.5
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 +24 -39
- package/dist/Model.js +177 -252
- package/dist/Obj.js +33 -39
- package/dist/ObserverStore.js +102 -128
- package/dist/PersistentStore.js +15 -17
- package/dist/PubSub.js +2 -2
- package/dist/ReactStore.js +40 -47
- package/dist/Store.js +58 -78
- package/dist/SubObj.js +31 -43
- package/dist/dataflux.min.js +1 -1
- package/dist/dataflux.min.js.map +1 -1
- package/dist/modelHooksUtils.js +2 -2
- package/package.json +13 -13
package/dist/ReactStore.js
CHANGED
|
@@ -15,23 +15,21 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
15
15
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
17
17
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
18
|
-
function
|
|
19
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
20
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
18
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
21
19
|
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); }
|
|
22
20
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
23
|
-
function _isNativeReflectConstruct() {
|
|
21
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
24
22
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
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
|
+
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(
|
|
27
|
-
function _toPrimitive(
|
|
26
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
27
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
28
28
|
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
29
29
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
30
30
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
31
|
-
function _classPrivateFieldGet(
|
|
32
|
-
function
|
|
33
|
-
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
34
|
-
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; } /*
|
|
31
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
32
|
+
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); } /*
|
|
35
33
|
* MIT License
|
|
36
34
|
*
|
|
37
35
|
* Copyright (c) 2022 Massimo Candela <https://massimocandela.com>
|
|
@@ -55,42 +53,37 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
|
|
|
55
53
|
* SOFTWARE.
|
|
56
54
|
*/
|
|
57
55
|
var _addSubscriptionToContext = /*#__PURE__*/new WeakMap();
|
|
58
|
-
var
|
|
56
|
+
var _ReactStore_brand = /*#__PURE__*/new WeakSet();
|
|
59
57
|
var ReactStore = exports["default"] = /*#__PURE__*/function (_ObserverStore) {
|
|
60
|
-
_inherits(ReactStore, _ObserverStore);
|
|
61
|
-
var _super = _createSuper(ReactStore);
|
|
62
58
|
function ReactStore(options) {
|
|
63
59
|
var _this;
|
|
64
60
|
_classCallCheck(this, ReactStore);
|
|
65
|
-
_this =
|
|
66
|
-
_classPrivateMethodInitSpec(
|
|
67
|
-
_classPrivateFieldInitSpec(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
context.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
var key = _step.value;
|
|
80
|
-
context.___obs_unsubscribe_context.unsubscribe(key);
|
|
81
|
-
}
|
|
82
|
-
} catch (err) {
|
|
83
|
-
_iterator.e(err);
|
|
84
|
-
} finally {
|
|
85
|
-
_iterator.f();
|
|
61
|
+
_this = _callSuper(this, ReactStore, [options]);
|
|
62
|
+
_classPrivateMethodInitSpec(_this, _ReactStore_brand);
|
|
63
|
+
_classPrivateFieldInitSpec(_this, _addSubscriptionToContext, function (context, subKey) {
|
|
64
|
+
// I know...
|
|
65
|
+
context.___obs_subkeys = context.___obs_subkeys || [];
|
|
66
|
+
context.___obs_subkeys.push(subKey);
|
|
67
|
+
context.___obs_unsubscribe_context = _this;
|
|
68
|
+
context.___obs_unsubscribe = function () {
|
|
69
|
+
var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
|
|
70
|
+
_step;
|
|
71
|
+
try {
|
|
72
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
73
|
+
var key = _step.value;
|
|
74
|
+
context.___obs_unsubscribe_context.unsubscribe(key);
|
|
86
75
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
76
|
+
} catch (err) {
|
|
77
|
+
_iterator.e(err);
|
|
78
|
+
} finally {
|
|
79
|
+
_iterator.f();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
context.componentWillUnmount = function () {
|
|
83
|
+
context.___obs_unsubscribe();
|
|
84
|
+
};
|
|
92
85
|
});
|
|
93
|
-
_defineProperty(
|
|
86
|
+
_defineProperty(_this, "handleChange", function (object, name, cast) {
|
|
94
87
|
return function (event, rawValue) {
|
|
95
88
|
var value = event ? event.target.type === "checkbox" ? event.target.checked : event.target.value : "";
|
|
96
89
|
var finalValue = value !== null && value !== void 0 ? value : rawValue;
|
|
@@ -99,32 +92,32 @@ var ReactStore = exports["default"] = /*#__PURE__*/function (_ObserverStore) {
|
|
|
99
92
|
});
|
|
100
93
|
return _this;
|
|
101
94
|
}
|
|
102
|
-
|
|
95
|
+
_inherits(ReactStore, _ObserverStore);
|
|
96
|
+
return _createClass(ReactStore, [{
|
|
103
97
|
key: "findAll",
|
|
104
98
|
value: function findAll(type, stateAttribute, context, filterFunction) {
|
|
105
|
-
|
|
99
|
+
_assertClassBrand(_ReactStore_brand, this, _fixState).call(this, stateAttribute, context, false);
|
|
106
100
|
var subKey = this.subscribe(type, function (data) {
|
|
107
101
|
if (context._isMounted === undefined || context._isMounted) {
|
|
108
102
|
context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data || [])));
|
|
109
103
|
}
|
|
110
104
|
}, filterFunction);
|
|
111
|
-
_classPrivateFieldGet(
|
|
105
|
+
_classPrivateFieldGet(_addSubscriptionToContext, this).call(this, context, subKey);
|
|
112
106
|
}
|
|
113
107
|
}, {
|
|
114
108
|
key: "findOne",
|
|
115
109
|
value: function findOne(type, stateAttribute, context, filterFunction) {
|
|
116
|
-
|
|
110
|
+
_assertClassBrand(_ReactStore_brand, this, _fixState).call(this, stateAttribute, context, true);
|
|
117
111
|
var subKey = this.subscribe(type, function (data) {
|
|
118
112
|
if (context._isMounted === undefined || context._isMounted) {
|
|
119
113
|
context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data && data.length ? data[0] : null)));
|
|
120
114
|
}
|
|
121
115
|
}, filterFunction);
|
|
122
|
-
_classPrivateFieldGet(
|
|
116
|
+
_classPrivateFieldGet(_addSubscriptionToContext, this).call(this, context, subKey);
|
|
123
117
|
}
|
|
124
118
|
}]);
|
|
125
|
-
return ReactStore;
|
|
126
119
|
}(_ObserverStore2["default"]);
|
|
127
|
-
function
|
|
120
|
+
function _fixState(stateAttribute, context, one) {
|
|
128
121
|
if (!context[stateAttribute]) {
|
|
129
122
|
context[stateAttribute] = one ? null : []; // side effect on state
|
|
130
123
|
}
|
package/dist/Store.js
CHANGED
|
@@ -19,12 +19,10 @@ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclarati
|
|
|
19
19
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
20
20
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
21
21
|
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; }
|
|
22
|
-
function _toPropertyKey(
|
|
23
|
-
function _toPrimitive(
|
|
24
|
-
function _classPrivateFieldGet(
|
|
25
|
-
function
|
|
26
|
-
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
27
|
-
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; } /*
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
23
|
+
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); }
|
|
24
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
25
|
+
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"); } /*
|
|
28
26
|
* MIT License
|
|
29
27
|
*
|
|
30
28
|
* Copyright (c) 2022 Massimo Candela <https://massimocandela.com>
|
|
@@ -50,11 +48,9 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
|
|
|
50
48
|
var objectStatuses = ["new", "old", "mock", "deleted"];
|
|
51
49
|
var _merge = /*#__PURE__*/new WeakMap();
|
|
52
50
|
var _wipe = /*#__PURE__*/new WeakMap();
|
|
53
|
-
var
|
|
51
|
+
var _Store_brand = /*#__PURE__*/new WeakSet();
|
|
54
52
|
var _deleteByObject = /*#__PURE__*/new WeakMap();
|
|
55
|
-
var _deleteByFilter = /*#__PURE__*/new WeakSet();
|
|
56
53
|
var _insertObject = /*#__PURE__*/new WeakMap();
|
|
57
|
-
var _loadObjects = /*#__PURE__*/new WeakSet();
|
|
58
54
|
var Store = exports["default"] = /*#__PURE__*/function () {
|
|
59
55
|
function Store() {
|
|
60
56
|
var _this = this,
|
|
@@ -64,9 +60,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
64
60
|
_options$batchPersist;
|
|
65
61
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
66
62
|
_classCallCheck(this, Store);
|
|
67
|
-
_classPrivateMethodInitSpec(this,
|
|
68
|
-
_classPrivateMethodInitSpec(this, _deleteByFilter);
|
|
69
|
-
_classPrivateMethodInitSpec(this, _error);
|
|
63
|
+
_classPrivateMethodInitSpec(this, _Store_brand);
|
|
70
64
|
_defineProperty(this, "getModels", function () {
|
|
71
65
|
return Object.keys(_this.models);
|
|
72
66
|
});
|
|
@@ -111,8 +105,8 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
111
105
|
if (oldFingerprint !== newFingerprint) {
|
|
112
106
|
// Nothing to do otherwise
|
|
113
107
|
if (force) {
|
|
114
|
-
_classPrivateFieldGet(
|
|
115
|
-
_classPrivateFieldGet(
|
|
108
|
+
_classPrivateFieldGet(_wipe, _this).call(_this, currentObject.object);
|
|
109
|
+
_classPrivateFieldGet(_merge, _this).call(_this, currentObject.object, wrapper.toJSON());
|
|
116
110
|
currentObject.fingerprint = newFingerprint;
|
|
117
111
|
updated.push(currentObject.object);
|
|
118
112
|
} else if (_this.hasChanged(type, currentObject.object)) {// Was the object edited locally?
|
|
@@ -120,13 +114,13 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
120
114
|
// Nothing for now
|
|
121
115
|
} else {
|
|
122
116
|
// Update with the new object
|
|
123
|
-
_classPrivateFieldGet(
|
|
117
|
+
_classPrivateFieldGet(_merge, _this).call(_this, currentObject.object, wrapper.toJSON());
|
|
124
118
|
currentObject.fingerprint = newFingerprint;
|
|
125
119
|
updated.push(currentObject.object);
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
122
|
} else {
|
|
129
|
-
var newObject = _classPrivateFieldGet(
|
|
123
|
+
var newObject = _classPrivateFieldGet(_insertObject, _this).call(_this, type, object, "old");
|
|
130
124
|
item.storedObjects[newObject.getId()].deleted = false;
|
|
131
125
|
inserted.push(newObject);
|
|
132
126
|
}
|
|
@@ -150,61 +144,49 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
150
144
|
return item.promise;
|
|
151
145
|
});
|
|
152
146
|
});
|
|
153
|
-
_classPrivateFieldInitSpec(this, _merge, {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
for (var key in newObject) {
|
|
157
|
-
originalObject[key] = newObject[key];
|
|
158
|
-
}
|
|
147
|
+
_classPrivateFieldInitSpec(this, _merge, function (originalObject, newObject) {
|
|
148
|
+
for (var key in newObject) {
|
|
149
|
+
originalObject[key] = newObject[key];
|
|
159
150
|
}
|
|
160
151
|
});
|
|
161
|
-
_classPrivateFieldInitSpec(this, _wipe, {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (key !== "id" && typeof originalObject[key] !== "function") {
|
|
166
|
-
delete originalObject[key];
|
|
167
|
-
}
|
|
152
|
+
_classPrivateFieldInitSpec(this, _wipe, function (originalObject) {
|
|
153
|
+
for (var key in originalObject) {
|
|
154
|
+
if (key !== "id" && typeof originalObject[key] !== "function") {
|
|
155
|
+
delete originalObject[key];
|
|
168
156
|
}
|
|
169
157
|
}
|
|
170
158
|
});
|
|
171
|
-
_classPrivateFieldInitSpec(this, _deleteByObject, {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
};
|
|
178
|
-
return _classPrivateMethodGet(_this, _deleteByFilter, _deleteByFilter2).call(_this, object.getModel().getType(), filterFunction);
|
|
179
|
-
}
|
|
159
|
+
_classPrivateFieldInitSpec(this, _deleteByObject, function (object) {
|
|
160
|
+
var id = object.getId();
|
|
161
|
+
var filterFunction = function filterFunction(item) {
|
|
162
|
+
return id === item.getId();
|
|
163
|
+
};
|
|
164
|
+
return _assertClassBrand(_Store_brand, _this, _deleteByFilter).call(_this, object.getModel().getType(), filterFunction);
|
|
180
165
|
});
|
|
181
|
-
_classPrivateFieldInitSpec(this, _insertObject, {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
_this.update([wrapper]);
|
|
197
|
-
delete wrapper.insert;
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
_this.models[type].storedObjects[id] = {
|
|
201
|
-
id: id,
|
|
202
|
-
fingerprint: wrapper.getFingerprint(),
|
|
203
|
-
object: wrapper,
|
|
204
|
-
status: status
|
|
166
|
+
_classPrivateFieldInitSpec(this, _insertObject, function (type, item, status) {
|
|
167
|
+
var model = _this.models[type].model;
|
|
168
|
+
var wrapper = new _Obj["default"](item, model);
|
|
169
|
+
var id = wrapper.getId();
|
|
170
|
+
if (_this.models[type].storedObjects[id]) {
|
|
171
|
+
throw new Error("The IDs provided for the model ".concat(type, " are not unique"));
|
|
172
|
+
}
|
|
173
|
+
if (!objectStatuses.includes(status)) {
|
|
174
|
+
throw new Error("The provided status is not valid");
|
|
175
|
+
}
|
|
176
|
+
if (status === "mock") {
|
|
177
|
+
wrapper.insert = function () {
|
|
178
|
+
_this.models[type].storedObjects[id].status = "new";
|
|
179
|
+
_this.update([wrapper]);
|
|
180
|
+
delete wrapper.insert;
|
|
205
181
|
};
|
|
206
|
-
return wrapper;
|
|
207
182
|
}
|
|
183
|
+
_this.models[type].storedObjects[id] = {
|
|
184
|
+
id: id,
|
|
185
|
+
fingerprint: wrapper.getFingerprint(),
|
|
186
|
+
object: wrapper,
|
|
187
|
+
status: status
|
|
188
|
+
};
|
|
189
|
+
return wrapper;
|
|
208
190
|
});
|
|
209
191
|
this.options = {
|
|
210
192
|
axios: (_options$axios = options.axios) !== null && _options$axios !== void 0 ? _options$axios : null,
|
|
@@ -217,7 +199,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
217
199
|
this.models = {};
|
|
218
200
|
this.pubSub = new _PubSub["default"]();
|
|
219
201
|
}
|
|
220
|
-
_createClass(Store, [{
|
|
202
|
+
return _createClass(Store, [{
|
|
221
203
|
key: "on",
|
|
222
204
|
value: function on(channel, callback) {
|
|
223
205
|
this.pubSub.subscribe(channel, callback);
|
|
@@ -248,7 +230,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
248
230
|
if (lazyLoad) {
|
|
249
231
|
resolve();
|
|
250
232
|
} else {
|
|
251
|
-
resolve(
|
|
233
|
+
resolve(_assertClassBrand(_Store_brand, _this2, _loadObjects).call(_this2, type));
|
|
252
234
|
}
|
|
253
235
|
} else {
|
|
254
236
|
var error = "The model already exists";
|
|
@@ -267,10 +249,10 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
267
249
|
value: function _delete(typeOrObjects, filterFunction) {
|
|
268
250
|
if (typeof typeOrObjects === "string" && typeof filterFunction === "function") {
|
|
269
251
|
var type = typeOrObjects;
|
|
270
|
-
return
|
|
252
|
+
return _assertClassBrand(_Store_brand, this, _deleteByFilter).call(this, type, filterFunction);
|
|
271
253
|
} else if (Array.isArray(typeOrObjects) && typeOrObjects.length && !filterFunction) {
|
|
272
254
|
var objects = typeOrObjects;
|
|
273
|
-
return Promise.all(objects.map(_classPrivateFieldGet(
|
|
255
|
+
return Promise.all(objects.map(_classPrivateFieldGet(_deleteByObject, this))).then(function (data) {
|
|
274
256
|
return data.flat();
|
|
275
257
|
});
|
|
276
258
|
} else {
|
|
@@ -285,7 +267,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
285
267
|
var _this3 = this;
|
|
286
268
|
return this._getPromise(type).then(function () {
|
|
287
269
|
return objects.map(function (object) {
|
|
288
|
-
return _classPrivateFieldGet(
|
|
270
|
+
return _classPrivateFieldGet(_insertObject, _this3).call(_this3, type, object, "new");
|
|
289
271
|
});
|
|
290
272
|
});
|
|
291
273
|
}
|
|
@@ -295,7 +277,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
295
277
|
var _this4 = this;
|
|
296
278
|
return this._getPromise(type).then(function () {
|
|
297
279
|
return objects.map(function (object) {
|
|
298
|
-
return _classPrivateFieldGet(
|
|
280
|
+
return _classPrivateFieldGet(_insertObject, _this4).call(_this4, type, object, "mock");
|
|
299
281
|
});
|
|
300
282
|
});
|
|
301
283
|
}
|
|
@@ -377,7 +359,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
377
359
|
key: "hasChanged",
|
|
378
360
|
value: function hasChanged(type, object) {
|
|
379
361
|
var obj = this.models[type].storedObjects[object.getId()];
|
|
380
|
-
return obj.fingerprint !== obj.object.getFingerprint();
|
|
362
|
+
return !obj || obj.fingerprint !== obj.object.getFingerprint();
|
|
381
363
|
}
|
|
382
364
|
}, {
|
|
383
365
|
key: "preload",
|
|
@@ -403,7 +385,6 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
403
385
|
updated.push(object);
|
|
404
386
|
} // Nothing for mock objects
|
|
405
387
|
}
|
|
406
|
-
|
|
407
388
|
return {
|
|
408
389
|
inserted: inserted,
|
|
409
390
|
updated: updated,
|
|
@@ -426,7 +407,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
426
407
|
try {
|
|
427
408
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
428
409
|
var _item = _step4.value;
|
|
429
|
-
_classPrivateFieldGet(
|
|
410
|
+
_classPrivateFieldGet(_insertObject, _this9).call(_this9, type, _item, "old");
|
|
430
411
|
}
|
|
431
412
|
} catch (err) {
|
|
432
413
|
_iterator4.e(err);
|
|
@@ -450,7 +431,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
450
431
|
} else if (!this.models[type].promise && !this.options.lazyLoad) {
|
|
451
432
|
return Promise.reject("The model is not loaded");
|
|
452
433
|
} else if (!this.models[type].promise && this.options.lazyLoad && !ifLoaded) {
|
|
453
|
-
return
|
|
434
|
+
return _assertClassBrand(_Store_brand, this, _loadObjects).call(this, type).then(function () {
|
|
454
435
|
return _this10.models[type].promise;
|
|
455
436
|
});
|
|
456
437
|
} else if (!this.models[type].promise && this.options.lazyLoad && ifLoaded) {
|
|
@@ -460,14 +441,13 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
460
441
|
}
|
|
461
442
|
}
|
|
462
443
|
}]);
|
|
463
|
-
return Store;
|
|
464
444
|
}();
|
|
465
|
-
function
|
|
445
|
+
function _error(error) {
|
|
466
446
|
error = error.message || error;
|
|
467
447
|
this.pubSub.publish("error", error);
|
|
468
448
|
return Promise.reject(error);
|
|
469
449
|
}
|
|
470
|
-
function
|
|
450
|
+
function _deleteByFilter(type, filterFunction) {
|
|
471
451
|
var _this11 = this;
|
|
472
452
|
return this._getPromise(type).then(function () {
|
|
473
453
|
var deleted = Object.values(_this11.models[type].storedObjects).filter(function (i) {
|
|
@@ -490,7 +470,7 @@ function _deleteByFilter2(type, filterFunction) {
|
|
|
490
470
|
});
|
|
491
471
|
});
|
|
492
472
|
}
|
|
493
|
-
function
|
|
473
|
+
function _loadObjects(type) {
|
|
494
474
|
var _this12 = this;
|
|
495
475
|
var item = this.models[type];
|
|
496
476
|
this.pubSub.publish("loading", {
|
|
@@ -503,7 +483,7 @@ function _loadObjects2(type) {
|
|
|
503
483
|
try {
|
|
504
484
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
505
485
|
var _item2 = _step6.value;
|
|
506
|
-
_classPrivateFieldGet(
|
|
486
|
+
_classPrivateFieldGet(_insertObject, _this12).call(_this12, type, _item2, "old");
|
|
507
487
|
}
|
|
508
488
|
} catch (err) {
|
|
509
489
|
_iterator6.e(err);
|
package/dist/SubObj.js
CHANGED
|
@@ -9,25 +9,23 @@ var _BasicObj2 = require("./BasicObj");
|
|
|
9
9
|
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, _toPropertyKey(descriptor.key), descriptor); } }
|
|
10
10
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
function
|
|
13
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
14
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
12
|
+
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
15
13
|
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); }
|
|
16
14
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
17
|
-
function _isNativeReflectConstruct() {
|
|
15
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
16
|
+
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); }
|
|
17
|
+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
18
18
|
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); }
|
|
19
19
|
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
|
20
20
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
21
21
|
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; }
|
|
22
|
-
function _toPropertyKey(
|
|
23
|
-
function _toPrimitive(
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
23
|
+
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); }
|
|
24
24
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
25
25
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
26
|
-
function _classPrivateFieldGet(
|
|
27
|
-
function
|
|
28
|
-
function
|
|
29
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
30
|
-
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } } /*
|
|
26
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
27
|
+
function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
|
|
28
|
+
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"); } /*
|
|
31
29
|
* MIT License
|
|
32
30
|
*
|
|
33
31
|
* Copyright (c) 2022 Massimo Candela <https://massimocandela.com>
|
|
@@ -54,49 +52,39 @@ var _model = /*#__PURE__*/new WeakMap();
|
|
|
54
52
|
var _parent = /*#__PURE__*/new WeakMap();
|
|
55
53
|
var _parentField = /*#__PURE__*/new WeakMap();
|
|
56
54
|
var SubObj = exports["default"] = /*#__PURE__*/function (_BasicObj) {
|
|
57
|
-
_inherits(SubObj, _BasicObj);
|
|
58
|
-
var _super = _createSuper(SubObj);
|
|
59
55
|
function SubObj(parent, field, values, model) {
|
|
60
|
-
var
|
|
56
|
+
var _this;
|
|
61
57
|
_classCallCheck(this, SubObj);
|
|
62
|
-
_this =
|
|
63
|
-
_classPrivateFieldInitSpec(
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
_this = _callSuper(this, SubObj, [values, model]);
|
|
59
|
+
_classPrivateFieldInitSpec(_this, _model, void 0);
|
|
60
|
+
_classPrivateFieldInitSpec(_this, _parent, void 0);
|
|
61
|
+
_classPrivateFieldInitSpec(_this, _parentField, void 0);
|
|
62
|
+
_defineProperty(_this, "set", function (attribute, value, hidden) {
|
|
63
|
+
return _get((_this, _getPrototypeOf(SubObj.prototype)), "set", _this).call(_this, attribute, value, hidden);
|
|
66
64
|
});
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
value: void 0
|
|
65
|
+
_defineProperty(_this, "save", function () {
|
|
66
|
+
return _classPrivateFieldGet(_model, _this).getStore().save([_classPrivateFieldGet(_parent, _this)]);
|
|
70
67
|
});
|
|
71
|
-
|
|
72
|
-
writable: true,
|
|
73
|
-
value: void 0
|
|
74
|
-
});
|
|
75
|
-
_defineProperty(_assertThisInitialized(_this), "set", function (attribute, value, hidden) {
|
|
76
|
-
return _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SubObj.prototype)), "set", _thisSuper).call(_thisSuper, attribute, value, hidden);
|
|
77
|
-
});
|
|
78
|
-
_defineProperty(_assertThisInitialized(_this), "save", function () {
|
|
79
|
-
return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore().save([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
|
|
80
|
-
});
|
|
81
|
-
_defineProperty(_assertThisInitialized(_this), "destroy", function () {
|
|
68
|
+
_defineProperty(_this, "destroy", function () {
|
|
82
69
|
var _classPrivateFieldGet2;
|
|
83
|
-
if (Array.isArray(_classPrivateFieldGet(
|
|
84
|
-
_classPrivateFieldGet(
|
|
70
|
+
if (Array.isArray(_classPrivateFieldGet(_parent, _this)[_classPrivateFieldGet(_parentField, _this)])) {
|
|
71
|
+
_classPrivateFieldGet(_parent, _this)[_classPrivateFieldGet(_parentField, _this)] = _classPrivateFieldGet(_parent, _this)[_classPrivateFieldGet(_parentField, _this)].filter(function (i) {
|
|
85
72
|
return i.getId() !== _this.getId();
|
|
86
73
|
});
|
|
87
|
-
} else if ((_classPrivateFieldGet2 = _classPrivateFieldGet(
|
|
88
|
-
_classPrivateFieldGet(
|
|
74
|
+
} else if ((_classPrivateFieldGet2 = _classPrivateFieldGet(_parent, _this)[_classPrivateFieldGet(_parentField, _this)]) !== null && _classPrivateFieldGet2 !== void 0 && _classPrivateFieldGet2.getId) {
|
|
75
|
+
_classPrivateFieldGet(_parent, _this)[_classPrivateFieldGet(_parentField, _this)] = null;
|
|
89
76
|
}
|
|
90
|
-
return _classPrivateFieldGet(
|
|
77
|
+
return _classPrivateFieldGet(_model, _this).getStore().update([_classPrivateFieldGet(_parent, _this)]);
|
|
91
78
|
});
|
|
92
|
-
_defineProperty(
|
|
93
|
-
return _classPrivateFieldGet(
|
|
79
|
+
_defineProperty(_this, "update", function () {
|
|
80
|
+
return _classPrivateFieldGet(_model, _this).getStore().update([_classPrivateFieldGet(_parent, _this)]);
|
|
94
81
|
});
|
|
95
|
-
_classPrivateFieldSet(
|
|
96
|
-
_classPrivateFieldSet(
|
|
97
|
-
_classPrivateFieldSet(
|
|
98
|
-
(0, _BasicObj2.setValues)(values, model, SubObj, _classPrivateFieldGet(
|
|
82
|
+
_classPrivateFieldSet(_model, _this, model);
|
|
83
|
+
_classPrivateFieldSet(_parent, _this, parent);
|
|
84
|
+
_classPrivateFieldSet(_parentField, _this, field);
|
|
85
|
+
(0, _BasicObj2.setValues)(values, model, SubObj, _classPrivateFieldGet(_parent, _this), _this);
|
|
99
86
|
return _this;
|
|
100
87
|
}
|
|
88
|
+
_inherits(SubObj, _BasicObj);
|
|
101
89
|
return _createClass(SubObj);
|
|
102
90
|
}(_BasicObj2.BasicObj);
|