dataflux 1.10.4 → 1.11.0

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.
@@ -1,66 +1,40 @@
1
1
  "use strict";
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = void 0;
9
-
10
8
  var _Store2 = _interopRequireDefault(require("./Store"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
10
  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; } } }; }
15
-
16
11
  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); }
17
-
18
12
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
19
-
20
13
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
-
22
14
  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, descriptor.key, descriptor); } }
23
-
24
15
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
25
-
26
16
  function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
27
-
28
17
  function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
29
-
30
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); }
31
-
32
19
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
33
-
34
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); }; }
35
-
36
21
  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); }
37
-
38
22
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
39
-
40
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; } }
41
-
42
24
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
-
44
25
  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; }
45
-
46
26
  var PersistentStore = /*#__PURE__*/function (_Store) {
47
27
  _inherits(PersistentStore, _Store);
48
-
49
28
  var _super = _createSuper(PersistentStore);
50
-
51
29
  function PersistentStore(options) {
52
30
  var _this;
53
-
54
31
  _classCallCheck(this, PersistentStore);
55
-
56
32
  _this = _super.call(this, options);
57
-
58
33
  _defineProperty(_assertThisInitialized(_this), "whenSaved", function (type) {
59
34
  return _this.getDiff(type).then(function (_ref) {
60
35
  var inserted = _ref.inserted,
61
- updated = _ref.updated,
62
- deleted = _ref.deleted;
63
-
36
+ updated = _ref.updated,
37
+ deleted = _ref.deleted;
64
38
  if (inserted.length === 0 && updated.length === 0 && deleted.length === 0) {
65
39
  return true;
66
40
  } else if (_this.options.autoSave) {
@@ -74,39 +48,30 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
74
48
  }
75
49
  });
76
50
  });
77
-
78
51
  _defineProperty(_assertThisInitialized(_this), "save", function () {
79
52
  _this._busy = true;
80
-
81
53
  _this.pubSub.publish("save", "start");
82
-
83
54
  if (_this._delayedSaveTimer) {
84
55
  clearTimeout(_this._delayedSaveTimer);
85
56
  }
86
-
87
57
  return Promise.all(Object.keys(_this.models).map(_this._saveByType)).then(function (data) {
88
58
  _this._busy = false;
89
-
90
59
  _this.pubSub.publish("save", "end");
91
-
92
60
  return data;
93
61
  })["catch"](function (error) {
94
62
  _this._busy = false;
95
-
96
63
  _this.pubSub.publish("save", "end");
97
-
98
64
  _this.pubSub.publish("error", error);
99
-
100
65
  return Promise.reject(error);
101
66
  });
102
67
  });
103
-
104
68
  _defineProperty(_assertThisInitialized(_this), "_saveDiff", function (type, _ref2) {
105
69
  var inserted = _ref2.inserted,
106
- updated = _ref2.updated,
107
- deleted = _ref2.deleted;
108
- var model = _this.models[type].model; // Validate objects
70
+ updated = _ref2.updated,
71
+ deleted = _ref2.deleted;
72
+ var model = _this.models[type].model;
109
73
 
74
+ // Validate objects
110
75
  var correctInserted = inserted.filter(function (object) {
111
76
  return model.isObjectValid(object.object);
112
77
  });
@@ -115,11 +80,12 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
115
80
  });
116
81
  var correctDeleted = deleted.filter(function (object) {
117
82
  return model.isObjectValid(object.object);
118
- }); // Operations order:
83
+ });
84
+
85
+ // Operations order:
119
86
  // 1) insert
120
87
  // 2) update
121
88
  // 3) delete
122
-
123
89
  return model.insertObjects(correctInserted.map(function (i) {
124
90
  return i.object;
125
91
  })).then(function () {
@@ -144,27 +110,22 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
144
110
  }, type);
145
111
  });
146
112
  });
147
-
148
113
  _defineProperty(_assertThisInitialized(_this), "_saveByType", function (type) {
149
114
  return _this.getDiff(type).then(function (diff) {
150
115
  return _this._saveDiff(type, diff);
151
116
  });
152
117
  });
153
-
154
118
  _defineProperty(_assertThisInitialized(_this), "delayedSave", function () {
155
119
  return new Promise(function (resolve, reject) {
156
120
  if (_this.options.autoSave) {
157
121
  if (_this._delayedSaveTimer) {
158
122
  if (_this._delayedSavePromise) {
159
123
  _this._delayedSavePromise();
160
-
161
124
  _this._delayedSavePromise = null;
162
125
  }
163
-
164
126
  clearTimeout(_this._delayedSaveTimer);
165
127
  _this._delayedSaveTimer = null;
166
128
  }
167
-
168
129
  _this._delayedSavePromise = resolve;
169
130
  _this._delayedSaveTimer = setTimeout(function () {
170
131
  resolve(_this.save());
@@ -175,11 +136,9 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
175
136
  }
176
137
  });
177
138
  });
178
-
179
139
  _this._busy = false;
180
140
  _this._delayedSaveTimer = null;
181
141
  _this._delayedSavePromise = null;
182
-
183
142
  if (typeof _this.options.autoSave === "number") {
184
143
  setInterval(function () {
185
144
  if (!_this._busy) {
@@ -187,15 +146,12 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
187
146
  }
188
147
  }, _this.options.autoSave);
189
148
  }
190
-
191
149
  return _this;
192
150
  }
193
-
194
151
  _createClass(PersistentStore, [{
195
152
  key: "addModel",
196
153
  value: function addModel(model) {
197
154
  var _this2 = this;
198
-
199
155
  this._busy = true;
200
156
  return _get(_getPrototypeOf(PersistentStore.prototype), "addModel", this).call(this, model).then(function () {
201
157
  _this2._busy = false;
@@ -205,7 +161,6 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
205
161
  key: "insert",
206
162
  value: function insert(type, objects) {
207
163
  var _this3 = this;
208
-
209
164
  return _get(_getPrototypeOf(PersistentStore.prototype), "insert", this).call(this, type, objects).then(function (data) {
210
165
  return _this3.delayedSave().then(function () {
211
166
  return data;
@@ -221,7 +176,6 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
221
176
  key: "delete",
222
177
  value: function _delete(typeOrObjects, filterFunction) {
223
178
  var _this4 = this;
224
-
225
179
  return _get(_getPrototypeOf(PersistentStore.prototype), "delete", this).call(this, typeOrObjects, filterFunction).then(function (data) {
226
180
  return _this4.delayedSave().then(function () {
227
181
  return data;
@@ -232,12 +186,10 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
232
186
  key: "update",
233
187
  value: function update(objects, skipSave) {
234
188
  var _this5 = this;
235
-
236
189
  return _get(_getPrototypeOf(PersistentStore.prototype), "update", this).call(this, objects).then(function (objects) {
237
190
  if (skipSave) {
238
191
  var _iterator = _createForOfIteratorHelper(objects),
239
- _step;
240
-
192
+ _step;
241
193
  try {
242
194
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
243
195
  var object = _step.value;
@@ -249,7 +201,6 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
249
201
  } finally {
250
202
  _iterator.f();
251
203
  }
252
-
253
204
  return objects;
254
205
  } else {
255
206
  return _this5.delayedSave().then(function () {
@@ -259,8 +210,6 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
259
210
  });
260
211
  }
261
212
  }]);
262
-
263
213
  return PersistentStore;
264
214
  }(_Store2["default"]);
265
-
266
215
  exports["default"] = PersistentStore;
package/dist/PubSub.js CHANGED
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
-
8
7
  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; } } }; }
9
-
10
8
  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); }
11
-
12
9
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13
-
14
10
  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, descriptor.key, descriptor); } }
15
-
16
11
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
17
-
18
12
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
-
20
13
  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; }
21
-
22
14
  /*
23
15
  * MIT License
24
16
  *
@@ -44,19 +36,14 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
44
36
  */
45
37
  var PubSub = /*#__PURE__*/_createClass(function PubSub() {
46
38
  var _this = this;
47
-
48
39
  _classCallCheck(this, PubSub);
49
-
50
40
  _defineProperty(this, "subscribe", function (channel, callback) {
51
41
  _this.callbacks[channel] = _this.callbacks[channel] || [];
52
-
53
42
  _this.callbacks[channel].push(callback);
54
43
  });
55
-
56
44
  _defineProperty(this, "publish", function (channel, content) {
57
45
  var _iterator = _createForOfIteratorHelper(_this.callbacks[channel] || []),
58
- _step;
59
-
46
+ _step;
60
47
  try {
61
48
  var _loop = function _loop() {
62
49
  var clb = _step.value;
@@ -65,7 +52,6 @@ var PubSub = /*#__PURE__*/_createClass(function PubSub() {
65
52
  resolve(true);
66
53
  })["catch"](console.log);
67
54
  };
68
-
69
55
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
70
56
  _loop();
71
57
  }
@@ -75,8 +61,6 @@ var PubSub = /*#__PURE__*/_createClass(function PubSub() {
75
61
  _iterator.f();
76
62
  }
77
63
  });
78
-
79
64
  this.callbacks = {};
80
65
  });
81
-
82
66
  exports["default"] = PubSub;
@@ -1,98 +1,58 @@
1
1
  "use strict";
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports["default"] = void 0;
9
-
10
8
  var _ObserverStore2 = _interopRequireDefault(require("./ObserverStore"));
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
10
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
-
16
11
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
17
-
18
12
  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; } } }; }
19
-
20
13
  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); }
21
-
22
14
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
23
-
24
15
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
-
26
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, descriptor.key, descriptor); } }
27
-
28
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; }
29
-
30
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); }
31
-
32
19
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
33
-
34
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); }; }
35
-
36
21
  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); }
37
-
38
22
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
39
-
40
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; } }
41
-
42
24
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
-
44
25
  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; }
45
-
46
26
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
47
-
48
27
  function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
49
-
50
28
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
51
-
52
29
  function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
53
-
54
30
  function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
55
-
56
31
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
57
-
58
32
  function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
59
-
60
33
  var _addSubscriptionToContext = /*#__PURE__*/new WeakMap();
61
-
62
34
  var _fixState = /*#__PURE__*/new WeakSet();
63
-
64
35
  var ReactStore = /*#__PURE__*/function (_ObserverStore) {
65
36
  _inherits(ReactStore, _ObserverStore);
66
-
67
37
  var _super = _createSuper(ReactStore);
68
-
69
38
  function ReactStore(options) {
70
39
  var _this;
71
-
72
40
  _classCallCheck(this, ReactStore);
73
-
74
41
  _this = _super.call(this, options);
75
-
76
42
  _classPrivateMethodInitSpec(_assertThisInitialized(_this), _fixState);
77
-
78
43
  _classPrivateFieldInitSpec(_assertThisInitialized(_this), _addSubscriptionToContext, {
79
44
  writable: true,
80
45
  value: function value(context, subKey) {
81
46
  // I know...
82
47
  context.___obs_subkeys = context.___obs_subkeys || [];
83
-
84
48
  context.___obs_subkeys.push(subKey);
85
-
86
49
  context.___obs_unsubscribe_context = _assertThisInitialized(_this);
87
-
88
50
  context.___obs_unsubscribe = function () {
89
51
  var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
90
- _step;
91
-
52
+ _step;
92
53
  try {
93
54
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
94
55
  var key = _step.value;
95
-
96
56
  context.___obs_unsubscribe_context.unsubscribe(key);
97
57
  }
98
58
  } catch (err) {
@@ -101,13 +61,11 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
101
61
  _iterator.f();
102
62
  }
103
63
  };
104
-
105
64
  context.componentWillUnmount = function () {
106
65
  context.___obs_unsubscribe();
107
66
  };
108
67
  }
109
68
  });
110
-
111
69
  _defineProperty(_assertThisInitialized(_this), "handleChange", function (object, name, cast) {
112
70
  return function (event, rawValue) {
113
71
  var value = event ? event.target.type === "checkbox" ? event.target.checked : event.target.value : "";
@@ -115,39 +73,30 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
115
73
  object.set(name, cast && finalValue != null ? cast(finalValue) : finalValue);
116
74
  };
117
75
  });
118
-
119
76
  return _this;
120
77
  }
121
-
122
78
  _createClass(ReactStore, [{
123
79
  key: "findAll",
124
80
  value: function findAll(type, stateAttribute, context, filterFunction) {
125
81
  _classPrivateMethodGet(this, _fixState, _fixState2).call(this, stateAttribute, context, false);
126
-
127
82
  var subKey = this.subscribe(type, function (data) {
128
83
  context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data || [])));
129
84
  }, filterFunction);
130
-
131
85
  _classPrivateFieldGet(this, _addSubscriptionToContext).call(this, context, subKey);
132
86
  }
133
87
  }, {
134
88
  key: "findOne",
135
89
  value: function findOne(type, stateAttribute, context, filterFunction) {
136
90
  _classPrivateMethodGet(this, _fixState, _fixState2).call(this, stateAttribute, context, true);
137
-
138
91
  var subKey = this.subscribe(type, function (data) {
139
92
  context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data && data.length ? data[0] : null)));
140
93
  }, filterFunction);
141
-
142
94
  _classPrivateFieldGet(this, _addSubscriptionToContext).call(this, context, subKey);
143
95
  }
144
96
  }]);
145
-
146
97
  return ReactStore;
147
98
  }(_ObserverStore2["default"]);
148
-
149
99
  exports["default"] = ReactStore;
150
-
151
100
  function _fixState2(stateAttribute, context, one) {
152
101
  if (!context[stateAttribute]) {
153
102
  context[stateAttribute] = one ? null : []; // side effect on state