dataflux 1.0.2

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.
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+
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
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _uuid = require("uuid");
11
+
12
+ var _batchPromises = _interopRequireDefault(require("batch-promises"));
13
+
14
+ var _PersistentStore2 = _interopRequireDefault(require("./PersistentStore"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
17
+
18
+ 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
+ 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
+ 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
+ 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); } }
25
+
26
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
27
+
28
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
29
+
30
+ 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
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
33
+
34
+ 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
+ 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
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
39
+
40
+ 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
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
43
+
44
+ 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
+ var ObserverStore = /*#__PURE__*/function (_PersistentStore) {
47
+ _inherits(ObserverStore, _PersistentStore);
48
+
49
+ var _super = _createSuper(ObserverStore);
50
+
51
+ function ObserverStore(options) {
52
+ var _this;
53
+
54
+ _classCallCheck(this, ObserverStore);
55
+
56
+ _this = _super.call(this, options);
57
+
58
+ _defineProperty(_assertThisInitialized(_this), "subscribe", function (type, callback, filterFunction) {
59
+ var subKey = (0, _uuid.v4)();
60
+
61
+ if (!_this.__subscribed[type]) {
62
+ _this.__subscribed[type] = {};
63
+ }
64
+
65
+ _this.find(type, filterFunction).then(function (data) {
66
+ _this._subscribeToObjects(type, data, {
67
+ callback: callback,
68
+ filterFunction: filterFunction,
69
+ subKey: subKey
70
+ });
71
+
72
+ return callback(data);
73
+ });
74
+
75
+ return subKey;
76
+ });
77
+
78
+ _defineProperty(_assertThisInitialized(_this), "unsubscribe", function (key) {
79
+ for (var type in _this.__subscribed) {
80
+ for (var id in _this.__subscribed[type]) {
81
+ _this.__subscribed[type][id] = _this.__subscribed[type][id].filter(function (i) {
82
+ return i.subKey !== key;
83
+ });
84
+
85
+ if (_this.__subscribed[type][id].length === 0) {
86
+ delete _this.__subscribed[type][id];
87
+ }
88
+ }
89
+ }
90
+ });
91
+
92
+ _defineProperty(_assertThisInitialized(_this), "_getUniqueSubs", function (objects, type) {
93
+ var out = {};
94
+
95
+ var _iterator = _createForOfIteratorHelper(objects),
96
+ _step;
97
+
98
+ try {
99
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
100
+ var object = _step.value;
101
+ var objectId = object.getId();
102
+ var typeChannel = _this.__subscribed[type] || {};
103
+ var subscribedToObject = typeChannel[objectId] || [];
104
+
105
+ var _iterator2 = _createForOfIteratorHelper(subscribedToObject),
106
+ _step2;
107
+
108
+ try {
109
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
110
+ var sub = _step2.value;
111
+ out[sub.subKey] = out[sub.subKey] || sub;
112
+ }
113
+ } catch (err) {
114
+ _iterator2.e(err);
115
+ } finally {
116
+ _iterator2.f();
117
+ }
118
+ }
119
+ } catch (err) {
120
+ _iterator.e(err);
121
+ } finally {
122
+ _iterator.f();
123
+ }
124
+
125
+ return Object.values(out);
126
+ });
127
+
128
+ _defineProperty(_assertThisInitialized(_this), "_propagateChange", function () {
129
+ var objects = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
130
+
131
+ if (objects.length) {
132
+ var type = objects[0].getModel().getType();
133
+
134
+ var uniqueSubs = _this._getUniqueSubs(objects, type);
135
+
136
+ (0, _batchPromises["default"])(10, uniqueSubs, function (_ref) {
137
+ var callback = _ref.callback,
138
+ filterFunction = _ref.filterFunction;
139
+ return _this.find(type, filterFunction).then(callback);
140
+ });
141
+ }
142
+ });
143
+
144
+ _defineProperty(_assertThisInitialized(_this), "_subscribeToObjects", function (type, objectsToSubscribe, item) {
145
+ var _iterator3 = _createForOfIteratorHelper(objectsToSubscribe),
146
+ _step3;
147
+
148
+ try {
149
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
150
+ var object = _step3.value;
151
+ var id = object.getId();
152
+
153
+ if (!_this.__subscribed[type][id]) {
154
+ _this.__subscribed[type][id] = [];
155
+ }
156
+
157
+ _this.__subscribed[type][id].push(item);
158
+ }
159
+ } catch (err) {
160
+ _iterator3.e(err);
161
+ } finally {
162
+ _iterator3.f();
163
+ }
164
+ });
165
+
166
+ _defineProperty(_assertThisInitialized(_this), "_propagateInsertChange", function (type, newObjects) {
167
+ var uniqueSubs = {};
168
+ var objects = Object.values(_this.__subscribed[type]);
169
+
170
+ for (var _i = 0, _objects = objects; _i < _objects.length; _i++) {
171
+ var object = _objects[_i];
172
+
173
+ var _iterator4 = _createForOfIteratorHelper(object),
174
+ _step4;
175
+
176
+ try {
177
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
178
+ var sub = _step4.value;
179
+
180
+ if (!uniqueSubs[sub.subKey]) {
181
+ uniqueSubs[sub.subKey] = sub;
182
+ }
183
+ }
184
+ } catch (err) {
185
+ _iterator4.e(err);
186
+ } finally {
187
+ _iterator4.f();
188
+ }
189
+ }
190
+
191
+ var possibleSubs = Object.values(uniqueSubs);
192
+ (0, _batchPromises["default"])(10, possibleSubs, function (_ref2) {
193
+ var callback = _ref2.callback,
194
+ filterFunction = _ref2.filterFunction;
195
+ var objectsToSubscribe = filterFunction ? newObjects.filter(filterFunction) : newObjects;
196
+
197
+ if (objectsToSubscribe.length) {
198
+ // Check if the new objects matter
199
+ return _this.find(type, filterFunction).then(function (data) {
200
+ var subKey;
201
+
202
+ var _iterator5 = _createForOfIteratorHelper(data),
203
+ _step5;
204
+
205
+ try {
206
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
207
+ var d = _step5.value;
208
+
209
+ var item = _this.__subscribed[d.getModel().getType()][d.getId()];
210
+
211
+ subKey = item ? item.subKey : null;
212
+ if (subKey) break;
213
+ }
214
+ } catch (err) {
215
+ _iterator5.e(err);
216
+ } finally {
217
+ _iterator5.f();
218
+ }
219
+
220
+ _this._subscribeToObjects(type, objectsToSubscribe, {
221
+ callback: callback,
222
+ filterFunction: filterFunction,
223
+ subKey: subKey
224
+ });
225
+
226
+ return data;
227
+ }).then(callback);
228
+ }
229
+ });
230
+ });
231
+
232
+ _defineProperty(_assertThisInitialized(_this), "trigger", function (event, objects) {
233
+ switch (event) {
234
+ case "insert":
235
+ if (objects[0]) _this._propagateInsertChange(objects[0].getModel().getType(), objects);
236
+ break;
237
+
238
+ case "update":
239
+ _this._propagateChange(objects);
240
+
241
+ break;
242
+
243
+ case "delete":
244
+ _this._propagateChange(objects);
245
+
246
+ break;
247
+ }
248
+
249
+ _this.delayedSave();
250
+ });
251
+
252
+ _this.__subscribed = {};
253
+ return _this;
254
+ }
255
+
256
+ return _createClass(ObserverStore);
257
+ }(_PersistentStore2["default"]);
258
+
259
+ var _default = ObserverStore;
260
+ exports["default"] = _default;
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+
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
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _Store2 = _interopRequireDefault(require("./Store"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
+
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; } } }; }
15
+
16
+ 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
+ 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
+ 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); } }
21
+
22
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
23
+
24
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
+
26
+ 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); }
27
+
28
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
+
30
+ 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); }; }
31
+
32
+ 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); }
33
+
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
+
36
+ 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; } }
37
+
38
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39
+
40
+ 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; }
41
+
42
+ var PersistentStore = /*#__PURE__*/function (_Store) {
43
+ _inherits(PersistentStore, _Store);
44
+
45
+ var _super = _createSuper(PersistentStore);
46
+
47
+ function PersistentStore(options) {
48
+ var _this;
49
+
50
+ _classCallCheck(this, PersistentStore);
51
+
52
+ _this = _super.call(this, options);
53
+
54
+ _defineProperty(_assertThisInitialized(_this), "_saveType", function (type) {
55
+ return _this._getSets(type).then(function (_ref) {
56
+ var inserted = _ref.inserted,
57
+ updated = _ref.updated,
58
+ deleted = _ref.deleted;
59
+ return _this.models[type].model.insertObjects(inserted).then(function () {
60
+ return _this.models[type].model.updateObjects(updated);
61
+ }).then(function () {
62
+ return _this.models[type].model.deleteObjects(deleted);
63
+ }).then(function () {
64
+ var _iterator = _createForOfIteratorHelper(deleted),
65
+ _step;
66
+
67
+ try {
68
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
69
+ var object = _step.value;
70
+ delete _this.models[type].storedObjects[object.id];
71
+ }
72
+ } catch (err) {
73
+ _iterator.e(err);
74
+ } finally {
75
+ _iterator.f();
76
+ }
77
+
78
+ var _iterator2 = _createForOfIteratorHelper(updated.concat(inserted)),
79
+ _step2;
80
+
81
+ try {
82
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
83
+ var _object = _step2.value;
84
+ _this.models[type].storedObjects[_object.id].fingerprint = _object.object.getFingerprint();
85
+ _this.models[type].storedObjects[_object.id].status = "old";
86
+ }
87
+ } catch (err) {
88
+ _iterator2.e(err);
89
+ } finally {
90
+ _iterator2.f();
91
+ }
92
+ });
93
+ });
94
+ });
95
+
96
+ _defineProperty(_assertThisInitialized(_this), "_getSets", function (type) {
97
+ return _this._getPromise(type).then(function () {
98
+ var objects = Object.values(_this.models[type].storedObjects);
99
+ var newObjects = objects.filter(function (object) {
100
+ return object.status === "new";
101
+ });
102
+ var edited = objects.filter(function (object) {
103
+ return object.status === "old" && object.fingerprint !== object.object.getFingerprint();
104
+ });
105
+ var deleted = objects.filter(function (object) {
106
+ return object.status === "deleted";
107
+ });
108
+ return {
109
+ inserted: newObjects,
110
+ updates: edited,
111
+ deleted: deleted
112
+ };
113
+ });
114
+ });
115
+
116
+ _defineProperty(_assertThisInitialized(_this), "save", function () {
117
+ return Promise.all(Object.keys(_this.models).map(_this._saveType));
118
+ });
119
+
120
+ _defineProperty(_assertThisInitialized(_this), "delayedSave", function () {
121
+ if (_this.options.autoSave) {
122
+ if (_this.__delayedSaveTimer) {
123
+ clearTimeout(_this.__delayedSaveTimer);
124
+ }
125
+
126
+ _this.__delayedSaveTimer = setTimeout(_this.save, _this.options.saveDelay);
127
+ }
128
+
129
+ return Promise.resolve();
130
+ });
131
+
132
+ _defineProperty(_assertThisInitialized(_this), "trigger", function (event, objects) {
133
+ if (["insert", "delete", "update"].includes(event)) {
134
+ _this.delayedSave();
135
+ }
136
+ });
137
+
138
+ if (typeof _this.options.autoSave === "number") {
139
+ setInterval(_this.delayedSave, _this.options.autoSave);
140
+ }
141
+
142
+ return _this;
143
+ }
144
+
145
+ return _createClass(PersistentStore);
146
+ }(_Store2["default"]);
147
+
148
+ exports["default"] = PersistentStore;
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+
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
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _ObserverStore2 = _interopRequireDefault(require("./ObserverStore"));
11
+
12
+ var _this = void 0;
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
+
16
+ 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; }
17
+
18
+ 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; }
19
+
20
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
+
22
+ 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
+ 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
+ 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); }
27
+
28
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
+
30
+ 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); }; }
31
+
32
+ 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); }
33
+
34
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35
+
36
+ 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; } }
37
+
38
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39
+
40
+ 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; }
41
+
42
+ 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; } } }; }
43
+
44
+ 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); }
45
+
46
+ 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; }
47
+
48
+ var addSubscriptionToContext = function addSubscriptionToContext(context, subKey) {
49
+ // I know...
50
+ context.___obs_subkeys = context.___obs_subkeys || [];
51
+
52
+ context.___obs_subkeys.push(subKey);
53
+
54
+ context.___obs_unsubscribe = function () {
55
+ var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
56
+ _step;
57
+
58
+ try {
59
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
60
+ var key = _step.value;
61
+
62
+ _this.unsubscribe(key);
63
+ }
64
+ } catch (err) {
65
+ _iterator.e(err);
66
+ } finally {
67
+ _iterator.f();
68
+ }
69
+ };
70
+
71
+ context.componentWillUnmount = function () {
72
+ context.___obs_unsubscribe();
73
+ };
74
+ };
75
+
76
+ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
77
+ _inherits(ReactStore, _ObserverStore);
78
+
79
+ var _super = _createSuper(ReactStore);
80
+
81
+ function ReactStore(options) {
82
+ var _this2;
83
+
84
+ _classCallCheck(this, ReactStore);
85
+
86
+ _this2 = _super.call(this, options);
87
+
88
+ _defineProperty(_assertThisInitialized(_this2), "handleChange", function (object, name) {
89
+ return function (event, rawValue) {
90
+ var value = event ? event.target.type === "checkbox" ? event.target.checked : event.target.value : "";
91
+ object.set(name, value || rawValue || "");
92
+ };
93
+ });
94
+
95
+ return _this2;
96
+ }
97
+
98
+ _createClass(ReactStore, [{
99
+ key: "findAll",
100
+ value: function findAll(type, stateAttribute, context, filterFunction) {
101
+ var subKey = this.subscribe(type, function (data) {
102
+ context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data)));
103
+ }, filterFunction);
104
+ addSubscriptionToContext(context, subKey);
105
+ }
106
+ }, {
107
+ key: "findOne",
108
+ value: function findOne(type, stateAttribute, context, filterFunction) {
109
+ var subKey = this.subscribe(type, function (data) {
110
+ context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data && data.length ? data[0] : null)));
111
+ }, filterFunction);
112
+ addSubscriptionToContext(context, subKey);
113
+ }
114
+ }]);
115
+
116
+ return ReactStore;
117
+ }(_ObserverStore2["default"]);
118
+
119
+ exports["default"] = ReactStore;