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/ReactStore.js
CHANGED
|
@@ -17,21 +17,19 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
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
18
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
19
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); }
|
|
20
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
20
21
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
21
22
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
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
|
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,41 +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
58
|
function ReactStore(options) {
|
|
62
59
|
var _this;
|
|
63
60
|
_classCallCheck(this, ReactStore);
|
|
64
61
|
_this = _callSuper(this, ReactStore, [options]);
|
|
65
|
-
_classPrivateMethodInitSpec(
|
|
66
|
-
_classPrivateFieldInitSpec(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
context.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
var key = _step.value;
|
|
79
|
-
context.___obs_unsubscribe_context.unsubscribe(key);
|
|
80
|
-
}
|
|
81
|
-
} catch (err) {
|
|
82
|
-
_iterator.e(err);
|
|
83
|
-
} finally {
|
|
84
|
-
_iterator.f();
|
|
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);
|
|
85
75
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
} catch (err) {
|
|
77
|
+
_iterator.e(err);
|
|
78
|
+
} finally {
|
|
79
|
+
_iterator.f();
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
context.componentWillUnmount = function () {
|
|
83
|
+
context.___obs_unsubscribe();
|
|
84
|
+
};
|
|
91
85
|
});
|
|
92
|
-
_defineProperty(
|
|
86
|
+
_defineProperty(_this, "handleChange", function (object, name, cast) {
|
|
93
87
|
return function (event, rawValue) {
|
|
94
88
|
var value = event ? event.target.type === "checkbox" ? event.target.checked : event.target.value : "";
|
|
95
89
|
var finalValue = value !== null && value !== void 0 ? value : rawValue;
|
|
@@ -98,32 +92,32 @@ var ReactStore = exports["default"] = /*#__PURE__*/function (_ObserverStore) {
|
|
|
98
92
|
});
|
|
99
93
|
return _this;
|
|
100
94
|
}
|
|
101
|
-
|
|
95
|
+
_inherits(ReactStore, _ObserverStore);
|
|
96
|
+
return _createClass(ReactStore, [{
|
|
102
97
|
key: "findAll",
|
|
103
98
|
value: function findAll(type, stateAttribute, context, filterFunction) {
|
|
104
|
-
|
|
99
|
+
_assertClassBrand(_ReactStore_brand, this, _fixState).call(this, stateAttribute, context, false);
|
|
105
100
|
var subKey = this.subscribe(type, function (data) {
|
|
106
101
|
if (context._isMounted === undefined || context._isMounted) {
|
|
107
102
|
context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data || [])));
|
|
108
103
|
}
|
|
109
104
|
}, filterFunction);
|
|
110
|
-
_classPrivateFieldGet(
|
|
105
|
+
_classPrivateFieldGet(_addSubscriptionToContext, this).call(this, context, subKey);
|
|
111
106
|
}
|
|
112
107
|
}, {
|
|
113
108
|
key: "findOne",
|
|
114
109
|
value: function findOne(type, stateAttribute, context, filterFunction) {
|
|
115
|
-
|
|
110
|
+
_assertClassBrand(_ReactStore_brand, this, _fixState).call(this, stateAttribute, context, true);
|
|
116
111
|
var subKey = this.subscribe(type, function (data) {
|
|
117
112
|
if (context._isMounted === undefined || context._isMounted) {
|
|
118
113
|
context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data && data.length ? data[0] : null)));
|
|
119
114
|
}
|
|
120
115
|
}, filterFunction);
|
|
121
|
-
_classPrivateFieldGet(
|
|
116
|
+
_classPrivateFieldGet(_addSubscriptionToContext, this).call(this, context, subKey);
|
|
122
117
|
}
|
|
123
118
|
}]);
|
|
124
|
-
return ReactStore;
|
|
125
119
|
}(_ObserverStore2["default"]);
|
|
126
|
-
function
|
|
120
|
+
function _fixState(stateAttribute, context, one) {
|
|
127
121
|
if (!context[stateAttribute]) {
|
|
128
122
|
context[stateAttribute] = one ? null : []; // side effect on state
|
|
129
123
|
}
|
package/dist/Store.js
CHANGED
|
@@ -8,6 +8,8 @@ exports["default"] = void 0;
|
|
|
8
8
|
var _Obj = _interopRequireDefault(require("./Obj"));
|
|
9
9
|
var _PubSub = _interopRequireDefault(require("./PubSub"));
|
|
10
10
|
var _batchPromises = _interopRequireDefault(require("batch-promises"));
|
|
11
|
+
var _SubObj = _interopRequireDefault(require("./SubObj"));
|
|
12
|
+
var _BasicObj = require("./BasicObj");
|
|
11
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
14
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
13
15
|
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); }
|
|
@@ -19,12 +21,10 @@ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclarati
|
|
|
19
21
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
20
22
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
21
23
|
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
23
25
|
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(
|
|
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; } /*
|
|
26
|
+
function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
|
|
27
|
+
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
28
|
* MIT License
|
|
29
29
|
*
|
|
30
30
|
* Copyright (c) 2022 Massimo Candela <https://massimocandela.com>
|
|
@@ -50,11 +50,9 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
|
|
|
50
50
|
var objectStatuses = ["new", "old", "mock", "deleted"];
|
|
51
51
|
var _merge = /*#__PURE__*/new WeakMap();
|
|
52
52
|
var _wipe = /*#__PURE__*/new WeakMap();
|
|
53
|
-
var
|
|
53
|
+
var _Store_brand = /*#__PURE__*/new WeakSet();
|
|
54
54
|
var _deleteByObject = /*#__PURE__*/new WeakMap();
|
|
55
|
-
var _deleteByFilter = /*#__PURE__*/new WeakSet();
|
|
56
55
|
var _insertObject = /*#__PURE__*/new WeakMap();
|
|
57
|
-
var _loadObjects = /*#__PURE__*/new WeakSet();
|
|
58
56
|
var Store = exports["default"] = /*#__PURE__*/function () {
|
|
59
57
|
function Store() {
|
|
60
58
|
var _this = this,
|
|
@@ -64,9 +62,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
64
62
|
_options$batchPersist;
|
|
65
63
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
66
64
|
_classCallCheck(this, Store);
|
|
67
|
-
_classPrivateMethodInitSpec(this,
|
|
68
|
-
_classPrivateMethodInitSpec(this, _deleteByFilter);
|
|
69
|
-
_classPrivateMethodInitSpec(this, _error);
|
|
65
|
+
_classPrivateMethodInitSpec(this, _Store_brand);
|
|
70
66
|
_defineProperty(this, "getModels", function () {
|
|
71
67
|
return Object.keys(_this.models);
|
|
72
68
|
});
|
|
@@ -111,8 +107,8 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
111
107
|
if (oldFingerprint !== newFingerprint) {
|
|
112
108
|
// Nothing to do otherwise
|
|
113
109
|
if (force) {
|
|
114
|
-
_classPrivateFieldGet(
|
|
115
|
-
_classPrivateFieldGet(
|
|
110
|
+
_classPrivateFieldGet(_wipe, _this).call(_this, currentObject.object);
|
|
111
|
+
_classPrivateFieldGet(_merge, _this).call(_this, currentObject.object, wrapper.toJSON());
|
|
116
112
|
currentObject.fingerprint = newFingerprint;
|
|
117
113
|
updated.push(currentObject.object);
|
|
118
114
|
} else if (_this.hasChanged(type, currentObject.object)) {// Was the object edited locally?
|
|
@@ -120,13 +116,13 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
120
116
|
// Nothing for now
|
|
121
117
|
} else {
|
|
122
118
|
// Update with the new object
|
|
123
|
-
_classPrivateFieldGet(
|
|
119
|
+
_classPrivateFieldGet(_merge, _this).call(_this, currentObject.object, wrapper.toJSON());
|
|
124
120
|
currentObject.fingerprint = newFingerprint;
|
|
125
121
|
updated.push(currentObject.object);
|
|
126
122
|
}
|
|
127
123
|
}
|
|
128
124
|
} else {
|
|
129
|
-
var newObject = _classPrivateFieldGet(
|
|
125
|
+
var newObject = _classPrivateFieldGet(_insertObject, _this).call(_this, type, object, "old");
|
|
130
126
|
item.storedObjects[newObject.getId()].deleted = false;
|
|
131
127
|
inserted.push(newObject);
|
|
132
128
|
}
|
|
@@ -150,61 +146,47 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
150
146
|
return item.promise;
|
|
151
147
|
});
|
|
152
148
|
});
|
|
153
|
-
_classPrivateFieldInitSpec(this, _merge, {
|
|
154
|
-
|
|
155
|
-
value: function value(originalObject, newObject) {
|
|
156
|
-
for (var key in newObject) {
|
|
157
|
-
originalObject[key] = newObject[key];
|
|
158
|
-
}
|
|
159
|
-
}
|
|
149
|
+
_classPrivateFieldInitSpec(this, _merge, function (originalObject, newObject) {
|
|
150
|
+
(0, _BasicObj.setValues)(newObject, originalObject.getModel(), _SubObj["default"], originalObject, originalObject);
|
|
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",
|
|
@@ -425,7 +407,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
425
407
|
try {
|
|
426
408
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
427
409
|
var _item = _step4.value;
|
|
428
|
-
_classPrivateFieldGet(
|
|
410
|
+
_classPrivateFieldGet(_insertObject, _this9).call(_this9, type, _item, "old");
|
|
429
411
|
}
|
|
430
412
|
} catch (err) {
|
|
431
413
|
_iterator4.e(err);
|
|
@@ -449,7 +431,7 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
449
431
|
} else if (!this.models[type].promise && !this.options.lazyLoad) {
|
|
450
432
|
return Promise.reject("The model is not loaded");
|
|
451
433
|
} else if (!this.models[type].promise && this.options.lazyLoad && !ifLoaded) {
|
|
452
|
-
return
|
|
434
|
+
return _assertClassBrand(_Store_brand, this, _loadObjects).call(this, type).then(function () {
|
|
453
435
|
return _this10.models[type].promise;
|
|
454
436
|
});
|
|
455
437
|
} else if (!this.models[type].promise && this.options.lazyLoad && ifLoaded) {
|
|
@@ -459,14 +441,13 @@ var Store = exports["default"] = /*#__PURE__*/function () {
|
|
|
459
441
|
}
|
|
460
442
|
}
|
|
461
443
|
}]);
|
|
462
|
-
return Store;
|
|
463
444
|
}();
|
|
464
|
-
function
|
|
445
|
+
function _error(error) {
|
|
465
446
|
error = error.message || error;
|
|
466
447
|
this.pubSub.publish("error", error);
|
|
467
448
|
return Promise.reject(error);
|
|
468
449
|
}
|
|
469
|
-
function
|
|
450
|
+
function _deleteByFilter(type, filterFunction) {
|
|
470
451
|
var _this11 = this;
|
|
471
452
|
return this._getPromise(type).then(function () {
|
|
472
453
|
var deleted = Object.values(_this11.models[type].storedObjects).filter(function (i) {
|
|
@@ -489,7 +470,7 @@ function _deleteByFilter2(type, filterFunction) {
|
|
|
489
470
|
});
|
|
490
471
|
});
|
|
491
472
|
}
|
|
492
|
-
function
|
|
473
|
+
function _loadObjects(type) {
|
|
493
474
|
var _this12 = this;
|
|
494
475
|
var item = this.models[type];
|
|
495
476
|
this.pubSub.publish("loading", {
|
|
@@ -502,7 +483,7 @@ function _loadObjects2(type) {
|
|
|
502
483
|
try {
|
|
503
484
|
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
504
485
|
var _item2 = _step6.value;
|
|
505
|
-
_classPrivateFieldGet(
|
|
486
|
+
_classPrivateFieldGet(_insertObject, _this12).call(_this12, type, _item2, "old");
|
|
506
487
|
}
|
|
507
488
|
} catch (err) {
|
|
508
489
|
_iterator6.e(err);
|
package/dist/SubObj.js
CHANGED
|
@@ -11,23 +11,21 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
11
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
12
|
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
13
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); }
|
|
14
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
15
14
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
15
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
16
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
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i :
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
23
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,48 +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
55
|
function SubObj(parent, field, values, model) {
|
|
59
|
-
var
|
|
56
|
+
var _this;
|
|
60
57
|
_classCallCheck(this, SubObj);
|
|
61
58
|
_this = _callSuper(this, SubObj, [values, model]);
|
|
62
|
-
_classPrivateFieldInitSpec(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
writable: true,
|
|
68
|
-
value: void 0
|
|
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);
|
|
69
64
|
});
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
value: void 0
|
|
65
|
+
_defineProperty(_this, "save", function () {
|
|
66
|
+
return _classPrivateFieldGet(_model, _this).getStore().save([_classPrivateFieldGet(_parent, _this)]);
|
|
73
67
|
});
|
|
74
|
-
_defineProperty(
|
|
75
|
-
return _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SubObj.prototype)), "set", _thisSuper).call(_thisSuper, attribute, value, hidden);
|
|
76
|
-
});
|
|
77
|
-
_defineProperty(_assertThisInitialized(_this), "save", function () {
|
|
78
|
-
return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore().save([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
|
|
79
|
-
});
|
|
80
|
-
_defineProperty(_assertThisInitialized(_this), "destroy", function () {
|
|
68
|
+
_defineProperty(_this, "destroy", function () {
|
|
81
69
|
var _classPrivateFieldGet2;
|
|
82
|
-
if (Array.isArray(_classPrivateFieldGet(
|
|
83
|
-
_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) {
|
|
84
72
|
return i.getId() !== _this.getId();
|
|
85
73
|
});
|
|
86
|
-
} else if ((_classPrivateFieldGet2 = _classPrivateFieldGet(
|
|
87
|
-
_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;
|
|
88
76
|
}
|
|
89
|
-
return _classPrivateFieldGet(
|
|
77
|
+
return _classPrivateFieldGet(_model, _this).getStore().update([_classPrivateFieldGet(_parent, _this)]);
|
|
90
78
|
});
|
|
91
|
-
_defineProperty(
|
|
92
|
-
return _classPrivateFieldGet(
|
|
79
|
+
_defineProperty(_this, "update", function () {
|
|
80
|
+
return _classPrivateFieldGet(_model, _this).getStore().update([_classPrivateFieldGet(_parent, _this)]);
|
|
93
81
|
});
|
|
94
|
-
_classPrivateFieldSet(
|
|
95
|
-
_classPrivateFieldSet(
|
|
96
|
-
_classPrivateFieldSet(
|
|
97
|
-
(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);
|
|
98
86
|
return _this;
|
|
99
87
|
}
|
|
88
|
+
_inherits(SubObj, _BasicObj);
|
|
100
89
|
return _createClass(SubObj);
|
|
101
90
|
}(_BasicObj2.BasicObj);
|