dataflux 1.9.2 → 1.9.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/Store.js CHANGED
@@ -43,8 +43,6 @@ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(
43
43
 
44
44
  var objectStatuses = ["new", "old", "mock", "deleted"];
45
45
 
46
- var _refreshObjectByType = /*#__PURE__*/new WeakMap();
47
-
48
46
  var _merge = /*#__PURE__*/new WeakMap();
49
47
 
50
48
  var _error = /*#__PURE__*/new WeakSet();
@@ -55,7 +53,7 @@ var _deleteByFilter = /*#__PURE__*/new WeakSet();
55
53
 
56
54
  var _getPromise = /*#__PURE__*/new WeakSet();
57
55
 
58
- var _insertObject = /*#__PURE__*/new WeakSet();
56
+ var _insertObject = /*#__PURE__*/new WeakMap();
59
57
 
60
58
  var _loadObjects = /*#__PURE__*/new WeakSet();
61
59
 
@@ -71,8 +69,6 @@ var Store = /*#__PURE__*/function () {
71
69
 
72
70
  _classPrivateMethodInitSpec(this, _loadObjects);
73
71
 
74
- _classPrivateMethodInitSpec(this, _insertObject);
75
-
76
72
  _classPrivateMethodInitSpec(this, _getPromise);
77
73
 
78
74
  _classPrivateMethodInitSpec(this, _deleteByFilter);
@@ -83,80 +79,80 @@ var Store = /*#__PURE__*/function () {
83
79
  return Object.keys(_this.models);
84
80
  });
85
81
 
86
- _defineProperty(this, "refresh", function (type) {
87
- if (type) {
88
- return _classPrivateFieldGet(_this, _refreshObjectByType).call(_this, type);
89
- } else {
90
- return Promise.all(Object.keys(_this.models).map(_classPrivateFieldGet(_this, _refreshObjectByType)));
91
- }
92
- });
82
+ _defineProperty(this, "refreshObjectByType", function (type) {
83
+ return _classPrivateMethodGet(_this, _getPromise, _getPromise2).call(_this, type).then(function () {
84
+ var item = _this.models[type];
85
+ var inserted = [];
86
+ var deleted = [];
87
+ var updated = [];
88
+ item.promise = item.model.retrieveAll()["catch"](function () {
89
+ var objects = Object.values(_this.models[type].storedObjects);
90
+ var list = [];
91
+ return (0, _batchPromises["default"])(4, objects, function (object) {
92
+ return item.model.factory(object.object).then(function (items) {
93
+ list = list.concat(items);
94
+ });
95
+ }).then(function () {
96
+ return list;
97
+ });
98
+ }).then(function (objects) {
99
+ var _iterator = _createForOfIteratorHelper(objects),
100
+ _step;
93
101
 
94
- _classPrivateFieldInitSpec(this, _refreshObjectByType, {
95
- writable: true,
96
- value: function value(type) {
97
- return _classPrivateMethodGet(_this, _getPromise, _getPromise2).call(_this, type).then(function () {
98
- var item = _this.models[type];
102
+ try {
103
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
104
+ var object = _step.value;
105
+ var wrapper = new _Obj["default"](object, item.model);
99
106
 
100
- _this.pubSub.publish("refresh", {
101
- status: "start",
102
- model: type
103
- });
107
+ var _id = wrapper.getId();
104
108
 
105
- item.promise = item.model.retrieveAll()["catch"](function () {
106
- var objects = Object.values(_this.models[type].storedObjects);
107
- var list = [];
108
- return (0, _batchPromises["default"])(4, objects, function (object) {
109
- return item.model.factory(object.object).then(function (items) {
110
- list = list.concat(items);
111
- });
112
- }).then(function () {
113
- return list;
114
- });
115
- }).then(function (objects) {
116
- var _iterator = _createForOfIteratorHelper(objects),
117
- _step;
118
-
119
- try {
120
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
121
- var object = _step.value;
122
- var wrapper = new _Obj["default"](object, item.model);
123
- var id = wrapper.getId();
124
- var currentObject = item === null || item === void 0 ? void 0 : item.storedObjects[id]; // console.log("currentObject", item);
125
-
126
- if (currentObject) {
127
- var newFingerprint = wrapper.getFingerprint();
128
- var oldFingerprint = currentObject.fingerprint;
129
-
130
- if (oldFingerprint !== newFingerprint) {
131
- // Nothing to do otherwise
132
- if (_this.hasChanged(type, currentObject.object)) {// Was the object edited locally?
133
- // Nothing for now
134
- } else {
135
- // Update with the new object
136
- // console.log("merge", wrapper);
137
- _classPrivateFieldGet(_this, _merge).call(_this, _this.models[type].storedObjects[id].object, wrapper.toJSON());
138
-
139
- _this.models[type].storedObjects[id].fingerprint = newFingerprint;
140
- }
109
+ var currentObject = item === null || item === void 0 ? void 0 : item.storedObjects[_id];
110
+
111
+ if (currentObject) {
112
+ currentObject.deleted = false;
113
+ var newFingerprint = wrapper.getFingerprint();
114
+ var oldFingerprint = currentObject.fingerprint;
115
+
116
+ if (oldFingerprint !== newFingerprint) {
117
+ // Nothing to do otherwise
118
+ if (_this.hasChanged(type, currentObject.object)) {// Was the object edited locally?
119
+ // Nothing for now
120
+ } else {
121
+ // Update with the new object
122
+ _classPrivateFieldGet(_this, _merge).call(_this, currentObject.object, wrapper.toJSON());
123
+
124
+ currentObject.fingerprint = newFingerprint;
125
+ updated.push(currentObject.object);
141
126
  }
142
- } else {
143
- _classPrivateMethodGet(_this, _insertObject, _insertObject2).call(_this, type, object, "old");
144
127
  }
128
+ } else {
129
+ var newObject = _classPrivateFieldGet(_this, _insertObject).call(_this, type, object, "old");
130
+
131
+ item.storedObjects[newObject.getId()].deleted = false;
132
+ inserted.push(newObject);
145
133
  }
146
- } catch (err) {
147
- _iterator.e(err);
148
- } finally {
149
- _iterator.f();
150
134
  }
135
+ } catch (err) {
136
+ _iterator.e(err);
137
+ } finally {
138
+ _iterator.f();
139
+ }
151
140
 
152
- _this.pubSub.publish("refresh", {
153
- status: "end",
154
- model: type
155
- });
156
- });
157
- return item.promise;
141
+ for (var id in item === null || item === void 0 ? void 0 : item.storedObjects) {
142
+ var obj = item.storedObjects[id];
143
+
144
+ if (obj.deleted === undefined) {
145
+ deleted.push(obj.object);
146
+ delete item.storedObjects[id];
147
+ } else {
148
+ delete obj.deleted;
149
+ }
150
+ }
151
+
152
+ return [inserted, updated, deleted];
158
153
  });
159
- }
154
+ return item.promise;
155
+ });
160
156
  });
161
157
 
162
158
  _classPrivateFieldInitSpec(this, _merge, {
@@ -164,9 +160,8 @@ var Store = /*#__PURE__*/function () {
164
160
  value: function value(originalObject, newObject) {
165
161
  for (var key in newObject) {
166
162
  originalObject[key] = newObject[key];
167
- }
163
+ } // originalObject.update();
168
164
 
169
- originalObject.update();
170
165
  }
171
166
  });
172
167
 
@@ -183,6 +178,41 @@ var Store = /*#__PURE__*/function () {
183
178
  }
184
179
  });
185
180
 
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
+
188
+ if (_this.models[type].storedObjects[id]) {
189
+ throw new Error("The IDs provided for the model ".concat(type, " are not unique"));
190
+ }
191
+
192
+ if (!objectStatuses.includes(status)) {
193
+ throw new Error("The provided status is not valid");
194
+ }
195
+
196
+ if (status === "mock") {
197
+ wrapper.insert = function () {
198
+ _this.models[type].storedObjects[id].status = "new";
199
+
200
+ _this.update([wrapper]);
201
+
202
+ delete wrapper.insert;
203
+ };
204
+ }
205
+
206
+ _this.models[type].storedObjects[id] = {
207
+ id: id,
208
+ fingerprint: wrapper.getFingerprint(),
209
+ object: wrapper,
210
+ status: status
211
+ };
212
+ return wrapper;
213
+ }
214
+ });
215
+
186
216
  this.options = {
187
217
  autoSave: (_options$autoSave = options.autoSave) !== null && _options$autoSave !== void 0 ? _options$autoSave : true,
188
218
  saveDelay: options.saveDelay || 1000,
@@ -191,10 +221,6 @@ var Store = /*#__PURE__*/function () {
191
221
  };
192
222
  this.models = {};
193
223
  this.pubSub = new _PubSub["default"]();
194
-
195
- if (this.options.autoRefresh && typeof this.options.autoRefresh === "number") {
196
- setInterval(this.refresh, this.options.autoRefresh);
197
- }
198
224
  }
199
225
 
200
226
  _createClass(Store, [{
@@ -274,7 +300,7 @@ var Store = /*#__PURE__*/function () {
274
300
 
275
301
  return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
276
302
  return objects.map(function (object) {
277
- return _classPrivateMethodGet(_this3, _insertObject, _insertObject2).call(_this3, type, object, "new");
303
+ return _classPrivateFieldGet(_this3, _insertObject).call(_this3, type, object, "new");
278
304
  });
279
305
  });
280
306
  }
@@ -285,7 +311,7 @@ var Store = /*#__PURE__*/function () {
285
311
 
286
312
  return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type).then(function () {
287
313
  return objects.map(function (object) {
288
- return _classPrivateMethodGet(_this4, _insertObject, _insertObject2).call(_this4, type, object, "mock");
314
+ return _classPrivateFieldGet(_this4, _insertObject).call(_this4, type, object, "mock");
289
315
  });
290
316
  });
291
317
  }
@@ -438,7 +464,7 @@ var Store = /*#__PURE__*/function () {
438
464
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
439
465
  var _item = _step4.value;
440
466
 
441
- _classPrivateMethodGet(_this9, _insertObject, _insertObject2).call(_this9, type, _item, "old");
467
+ _classPrivateFieldGet(_this9, _insertObject).call(_this9, type, _item, "old");
442
468
  }
443
469
  } catch (err) {
444
470
  _iterator4.e(err);
@@ -510,42 +536,8 @@ function _getPromise2(type) {
510
536
  }
511
537
  }
512
538
 
513
- function _insertObject2(type, item, status) {
514
- var _this12 = this;
515
-
516
- var model = this.models[type].model;
517
- var wrapper = new _Obj["default"](item, model);
518
- var id = wrapper.getId();
519
-
520
- if (this.models[type].storedObjects[id]) {
521
- throw new Error("The IDs provided for the model ".concat(type, " are not unique"));
522
- }
523
-
524
- if (!objectStatuses.includes(status)) {
525
- throw new Error("The provided status is not valid");
526
- }
527
-
528
- if (status === "mock") {
529
- wrapper.insert = function () {
530
- _this12.models[type].storedObjects[id].status = "new";
531
-
532
- _this12.update([wrapper]);
533
-
534
- delete wrapper.insert;
535
- };
536
- }
537
-
538
- this.models[type].storedObjects[id] = {
539
- id: id,
540
- fingerprint: wrapper.getFingerprint(),
541
- object: wrapper,
542
- status: status
543
- };
544
- return wrapper;
545
- }
546
-
547
539
  function _loadObjects2(type) {
548
- var _this13 = this;
540
+ var _this12 = this;
549
541
 
550
542
  var item = this.models[type];
551
543
  this.pubSub.publish("loading", {
@@ -560,7 +552,7 @@ function _loadObjects2(type) {
560
552
  for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
561
553
  var _item2 = _step6.value;
562
554
 
563
- _classPrivateMethodGet(_this13, _insertObject, _insertObject2).call(_this13, type, _item2, "old");
555
+ _classPrivateFieldGet(_this12, _insertObject).call(_this12, type, _item2, "old");
564
556
  }
565
557
  } catch (err) {
566
558
  _iterator6.e(err);
@@ -568,7 +560,7 @@ function _loadObjects2(type) {
568
560
  _iterator6.f();
569
561
  }
570
562
 
571
- _this13.pubSub.publish("loading", {
563
+ _this12.pubSub.publish("loading", {
572
564
  status: "end",
573
565
  model: type
574
566
  });
package/dist/SubObj.js CHANGED
@@ -17,7 +17,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
17
17
 
18
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
19
 
20
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
20
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
21
21
 
22
22
  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); }; }
23
23
 
@@ -27,7 +27,11 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
27
27
 
28
28
  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; } }
29
29
 
30
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
30
+ 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); }
31
+
32
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
33
+
34
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
31
35
 
32
36
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
33
37
 
@@ -57,7 +61,7 @@ var SubObj = /*#__PURE__*/function (_BasicObj) {
57
61
  var _super = _createSuper(SubObj);
58
62
 
59
63
  function SubObj(parent, field, values, model) {
60
- var _this;
64
+ var _thisSuper, _this;
61
65
 
62
66
  _classCallCheck(this, SubObj);
63
67
 
@@ -78,6 +82,10 @@ var SubObj = /*#__PURE__*/function (_BasicObj) {
78
82
  value: void 0
79
83
  });
80
84
 
85
+ _defineProperty(_assertThisInitialized(_this), "set", function (attribute, value, hidden) {
86
+ return _get((_thisSuper = _assertThisInitialized(_this), _getPrototypeOf(SubObj.prototype)), "set", _thisSuper).call(_thisSuper, attribute, value, hidden);
87
+ });
88
+
81
89
  _defineProperty(_assertThisInitialized(_this), "save", function () {
82
90
  return _classPrivateFieldGet(_assertThisInitialized(_this), _model).getStore().save([_classPrivateFieldGet(_assertThisInitialized(_this), _parent)]);
83
91
  });