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.
@@ -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 _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); }
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() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
27
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
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; }
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 _fixState = /*#__PURE__*/new WeakSet();
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 = _super.call(this, options);
66
- _classPrivateMethodInitSpec(_assertThisInitialized(_this), _fixState);
67
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _addSubscriptionToContext, {
68
- writable: true,
69
- value: function value(context, subKey) {
70
- // I know...
71
- context.___obs_subkeys = context.___obs_subkeys || [];
72
- context.___obs_subkeys.push(subKey);
73
- context.___obs_unsubscribe_context = _assertThisInitialized(_this);
74
- context.___obs_unsubscribe = function () {
75
- var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
76
- _step;
77
- try {
78
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
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
- context.componentWillUnmount = function () {
89
- context.___obs_unsubscribe();
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(_assertThisInitialized(_this), "handleChange", function (object, name, cast) {
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
- _createClass(ReactStore, [{
95
+ _inherits(ReactStore, _ObserverStore);
96
+ return _createClass(ReactStore, [{
103
97
  key: "findAll",
104
98
  value: function findAll(type, stateAttribute, context, filterFunction) {
105
- _classPrivateMethodGet(this, _fixState, _fixState2).call(this, stateAttribute, context, false);
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(this, _addSubscriptionToContext).call(this, context, subKey);
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
- _classPrivateMethodGet(this, _fixState, _fixState2).call(this, stateAttribute, context, true);
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(this, _addSubscriptionToContext).call(this, context, subKey);
116
+ _classPrivateFieldGet(_addSubscriptionToContext, this).call(this, context, subKey);
123
117
  }
124
118
  }]);
125
- return ReactStore;
126
119
  }(_ObserverStore2["default"]);
127
- function _fixState2(stateAttribute, context, one) {
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
23
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
24
- function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
25
- function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
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 _error = /*#__PURE__*/new WeakSet();
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, _loadObjects);
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(_this, _wipe).call(_this, currentObject.object);
115
- _classPrivateFieldGet(_this, _merge).call(_this, currentObject.object, wrapper.toJSON());
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(_this, _merge).call(_this, currentObject.object, wrapper.toJSON());
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(_this, _insertObject).call(_this, type, object, "old");
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
- writable: true,
155
- value: function value(originalObject, newObject) {
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
- writable: true,
163
- value: function value(originalObject) {
164
- for (var key in originalObject) {
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
- writable: true,
173
- value: function value(object) {
174
- var id = object.getId();
175
- var filterFunction = function filterFunction(item) {
176
- return id === item.getId();
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
- writable: true,
183
- value: function value(type, item, status) {
184
- var model = _this.models[type].model;
185
- var wrapper = new _Obj["default"](item, model);
186
- var id = wrapper.getId();
187
- if (_this.models[type].storedObjects[id]) {
188
- throw new Error("The IDs provided for the model ".concat(type, " are not unique"));
189
- }
190
- if (!objectStatuses.includes(status)) {
191
- throw new Error("The provided status is not valid");
192
- }
193
- if (status === "mock") {
194
- wrapper.insert = function () {
195
- _this.models[type].storedObjects[id].status = "new";
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(_classPrivateMethodGet(_this2, _loadObjects, _loadObjects2).call(_this2, type));
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 _classPrivateMethodGet(this, _deleteByFilter, _deleteByFilter2).call(this, type, filterFunction);
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(this, _deleteByObject))).then(function (data) {
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(_this3, _insertObject).call(_this3, type, object, "new");
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(_this4, _insertObject).call(_this4, type, object, "mock");
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(_this9, _insertObject).call(_this9, type, _item, "old");
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 _classPrivateMethodGet(this, _loadObjects, _loadObjects2).call(this, type).then(function () {
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 _error2(error) {
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 _deleteByFilter2(type, filterFunction) {
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 _loadObjects2(type) {
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(_this12, _insertObject).call(_this12, type, _item2, "old");
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 _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); }
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() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
23
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
27
- function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
28
- function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
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 _thisSuper, _this;
56
+ var _this;
61
57
  _classCallCheck(this, SubObj);
62
- _this = _super.call(this, values, model);
63
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _model, {
64
- writable: true,
65
- value: void 0
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
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _parent, {
68
- writable: true,
69
- value: void 0
65
+ _defineProperty(_this, "save", function () {
66
+ return _classPrivateFieldGet(_model, _this).getStore().save([_classPrivateFieldGet(_parent, _this)]);
70
67
  });
71
- _classPrivateFieldInitSpec(_assertThisInitialized(_this), _parentField, {
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(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)])) {
84
- _classPrivateFieldGet(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)] = _classPrivateFieldGet(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)].filter(function (i) {
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(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)]) !== null && _classPrivateFieldGet2 !== void 0 && _classPrivateFieldGet2.getId) {
88
- _classPrivateFieldGet(_assertThisInitialized(_this), _parent)[_classPrivateFieldGet(_assertThisInitialized(_this), _parentField)] = null;
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(_assertThisInitialized(_this), _model).getStore().update([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
77
+ return _classPrivateFieldGet(_model, _this).getStore().update([_classPrivateFieldGet(_parent, _this)]);
91
78
  });
92
- _defineProperty(_assertThisInitialized(_this), "update", function () {
93
- return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore().update([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
79
+ _defineProperty(_this, "update", function () {
80
+ return _classPrivateFieldGet(_model, _this).getStore().update([_classPrivateFieldGet(_parent, _this)]);
94
81
  });
95
- _classPrivateFieldSet(_assertThisInitialized(_this), _model, model);
96
- _classPrivateFieldSet(_assertThisInitialized(_this), _parent, parent);
97
- _classPrivateFieldSet(_assertThisInitialized(_this), _parentField, field);
98
- (0, _BasicObj2.setValues)(values, model, SubObj, _classPrivateFieldGet(_assertThisInitialized(_this), _parent), _assertThisInitialized(_this));
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);