dataflux 1.5.4 → 1.6.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.
package/CNAME ADDED
@@ -0,0 +1 @@
1
+ dataflux.js.org
package/README.md CHANGED
@@ -456,20 +456,21 @@ author1.getRelation("book", (book) => book.price < 20)
456
456
 
457
457
  The store has the following method.
458
458
 
459
- | Method | Description |
460
- |--------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
461
- | on(event, callback) | Method to subscribe to the events emitted by the store. See [events](#store-events) below. |
462
- | addModel(model) | Introduce a new model to the store. If lazyLoad = false (default), the model is populated with the objects coming from the API. |
463
- | get(type, id) | It allows to retrieve an object based on its type and store's ID (see `getId()` in [objects methods](#objects-methods). The type is the name of the model. |
464
- | find(type, filterFunction) | The promise-oriented method to access objects given a type and a filter function. If the filter function is missing, all the objects are returned. See [example 1](#example-1). |
465
- | delete(objects) | It deletes an array of objects. See [example 1](#example-3). |
466
- | delete(type, filterFunction) | It deleted objects given an array and a filter function. See [example 1](#example-3). |
467
- | insert(type, object) | It creates a new object of a given type and inserts it in the store. |
468
- | subscribe(type, callback, filterFunction) | The callback-oriented method to access objects given a type and a filter function. It returns the key of the subscription, needed to unsubscribe. If the filter function is missing, all the objects are returned. **DataFlux remembers your query and calls the callback every time any change is affecting the result of your query.** See [example 5](#example-5---observability). |
469
- | multipleSubscribe(subscriptions, callback) | A method to subscribe to multiple models. The first parameter is an array of models' names and filterFunctions, the second parameter is the callback to be called when the cumulative dataset is ready. E.g., `multipleSubscribe([["book", filterFunction1], ["author", filterFunction2]], callback)`. It returns the key of the subscription. See [example 5](#example-5---observability). |
470
- | unsubscribe(key) | Method to terminate a subscription given a subscription key. See [example 5](#example-5---observability). |
471
- | findOne(type, stateAttribute, context, filterFunction) | This method automatically injects and updates the React state with the requested data. If multiple objects satisfy the query, only the first is selected. The `stateAttribute` is the name of the attribute that will be added/updated in the state, the `context` is the React.Component. It automatically unsubscribe when the React.Component will unmount. See [example 6](#example-6---observability--react). |
472
- | findAll(type, stateAttribute, context, filterFunction) | This method automatically injects and updates the React state with the requested data. The `stateAttribute` is the name of the attribute that will be added/updated in the state, the `context` is the React.Component. It automatically unsubscribe when the React.Component will unmount. If the filter function is missing, all the objects are returned. See [example 6](#example-6---observability--react). |
459
+ | Method | Description |
460
+ |--------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
461
+ | on(event, callback) | Method to subscribe to the events emitted by the store. See [events](#store-events) below. |
462
+ | addModel(model) | Introduce a new model to the store. If lazyLoad = false (default), the model is populated with the objects coming from the API. |
463
+ | get(type, id) | It allows to retrieve an object based on its type and store's ID (see `getId()` in [objects methods](#objects-methods). The type is the name of the model. |
464
+ | find(type, filterFunction) | The promise-oriented method to access objects given a type and a filter function. If the filter function is missing, all the objects are returned. See [example 1](#example-1). |
465
+ | delete(objects) | It deletes an array of objects. See [example 1](#example-3). |
466
+ | delete(type, filterFunction) | It deleted objects given an array and a filter function. See [example 1](#example-3). |
467
+ | insert(type, object) | It creates a new object of a given type and inserts it in the store. |
468
+ | subscribe(type, callback, filterFunction) | The callback-oriented method to access objects given a type and a filter function. It returns the key of the subscription, needed to unsubscribe. If the filter function is missing, all the objects are returned. **DataFlux remembers your query and calls the callback every time any change is affecting the result of your query.** See [example 5](#example-5---observability). |
469
+ | multipleSubscribe(subscriptions, callback) | A method to subscribe to multiple models. The first parameter is an array of models' names and filterFunctions, the second parameter is the callback to be called when the cumulative dataset is ready. E.g., `multipleSubscribe([["book", filterFunction1], ["author", filterFunction2]], callback)`. It returns the key of the subscription. See [example 5](#example-5---observability). |
470
+ | unsubscribe(key) | Method to terminate a subscription given a subscription key. See [example 5](#example-5---observability). |
471
+ | findOne(type, stateAttribute, context, filterFunction) | This method automatically injects and updates the React state with the requested data. If multiple objects satisfy the query, only the first is selected. The `stateAttribute` is the name of the attribute that will be added/updated in the state, the `context` is the React.Component. It automatically unsubscribe when the React.Component will unmount. See [example 6](#example-6---observability--react). |
472
+ | findAll(type, stateAttribute, context, filterFunction) | This method automatically injects and updates the React state with the requested data. The `stateAttribute` is the name of the attribute that will be added/updated in the state, the `context` is the React.Component. It automatically unsubscribe when the React.Component will unmount. If the filter function is missing, all the objects are returned. See [example 6](#example-6---observability--react). |
473
+ | preload(type) | This method allows to preLoad all objects of a given model. If you initialize the store with `lazyLoad:true`, the objects of a model are retrieved from the API at the first query performed on that model (e.g., at the first `.find()`). However, sometimes you may want to speed up the first query by pre loading the objects of a specific model while keeping `lazyLoad:true` on the store; in such a case you can use `store.preload(type)`. |
473
474
 
474
475
  ## Store events
475
476
  The store emits the following events:
package/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
package/dist/BasicObj.js CHANGED
@@ -122,14 +122,16 @@ var BasicObj = /*#__PURE__*/_createClass(function BasicObj(values, model) {
122
122
  for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
123
123
  var a = _attrs[_i];
124
124
 
125
- if (_this[a] instanceof _moment["default"]) {
125
+ if (_this[a] == null) {
126
+ out[a] = _this[a];
127
+ } else if (_this[a] instanceof _moment["default"]) {
126
128
  out[a] = _this[a].toISOString();
127
129
  } else if (_this[a] instanceof Date) {
128
130
  out[a] = (0, _moment["default"])(_this[a]).toISOString();
129
- } else if (_this[a].toJSON) {
131
+ } else if (_typeof(_this[a]) === "object" && _this[a].toJSON) {
130
132
  out[a] = _this[a].toJSON();
131
133
  } else if (Array.isArray(_this[a]) && _this[a].every(function (i) {
132
- return i.toJSON;
134
+ return _typeof(i) === "object" && i.toJSON;
133
135
  })) {
134
136
  out[a] = _this[a].map(function (i) {
135
137
  return i.toJSON();
package/dist/Model.js CHANGED
@@ -11,6 +11,10 @@ var _batchPromises = _interopRequireDefault(require("batch-promises"));
11
11
 
12
12
  var _axios2 = _interopRequireDefault(require("axios"));
13
13
 
14
+ var _BasicObj = require("./BasicObj");
15
+
16
+ var _SubObj = _interopRequireDefault(require("./SubObj"));
17
+
14
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
19
 
16
20
  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); }
@@ -23,6 +27,10 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
23
27
 
24
28
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
25
29
 
30
+ 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; }
31
+
32
+ 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; }
33
+
26
34
  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(_e2) { throw _e2; }, 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(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
27
35
 
28
36
  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); }
@@ -194,7 +202,7 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
194
202
 
195
203
  _defineProperty(this, "load", function (obj) {
196
204
  if (_classPrivateFieldGet(_this, _loadFunction)) {
197
- return _this.getStore().whenSaved(_this.getType())["catch"](function () {
205
+ return _this.getStore().whenSaved(_this.getType())["catch"](function (e) {
198
206
  throw new Error("You cannot perform load() on an unsaved object.");
199
207
  }).then(function () {
200
208
  var res = _classPrivateFieldGet(_this, _loadFunction).call(_this, obj.toJSON());
@@ -211,7 +219,8 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
211
219
  return res;
212
220
  }
213
221
  }).then(function (data) {
214
- return applyData(obj, data);
222
+ (0, _BasicObj.setValues)(data, _this, _SubObj["default"], null, obj);
223
+ return data;
215
224
  })["catch"](function (error) {
216
225
  return _classPrivateMethodGet(_this, _error, _error2).call(_this, error);
217
226
  });
@@ -245,7 +254,7 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
245
254
  var filterRelation = _classPrivateFieldGet(_this, _includes)[includedType];
246
255
 
247
256
  if (filterRelation) {
248
- return parentObject.load()["catch"](function () {}).then(function () {
257
+ return (parentObject.getModel().options.load ? parentObject.load()["catch"](function () {}) : Promise.resolve()).then(function () {
249
258
  return _this.getStore().find(includedType, function (item) {
250
259
  return filterRelation(parentObject, item);
251
260
  }).then(function (data) {
@@ -376,20 +385,20 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
376
385
 
377
386
  _classPrivateFieldSet(this, _type, name);
378
387
 
379
- this.options = {
388
+ this.options = _objectSpread(_objectSpread({}, options), {}, {
380
389
  deep: (_options$deep = options.deep) !== null && _options$deep !== void 0 ? _options$deep : true,
381
390
  parseMoment: (_options$parseMoment = options.parseMoment) !== null && _options$parseMoment !== void 0 ? _options$parseMoment : false
382
- };
391
+ });
383
392
 
384
393
  _classPrivateFieldSet(this, _store, null);
385
394
 
386
395
  _classPrivateFieldSet(this, _includes, {});
387
396
 
388
- _classPrivateFieldSet(this, _axios, options.axios || _axios2["default"]);
397
+ _classPrivateFieldSet(this, _axios, this.options.axios || _axios2["default"]);
389
398
 
390
- _classPrivateFieldSet(this, _hiddenFields, options.hiddenFields || []);
399
+ _classPrivateFieldSet(this, _hiddenFields, this.options.hiddenFields || []);
391
400
 
392
- _classPrivateFieldSet(this, _loadFunction, options.load || null);
401
+ _classPrivateFieldSet(this, _loadFunction, this.options.load || null);
393
402
 
394
403
  if (!name || !options) {
395
404
  throw new Error("A Model requires at least a name and a hook");
@@ -11,6 +11,12 @@ var _Store2 = _interopRequireDefault(require("./Store"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
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
+
14
20
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
15
21
 
16
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); } }
@@ -196,12 +202,27 @@ var PersistentStore = /*#__PURE__*/function (_Store) {
196
202
  value: function update(objects, skipSave) {
197
203
  var _this5 = this;
198
204
 
199
- return _get(_getPrototypeOf(PersistentStore.prototype), "update", this).call(this, objects).then(function (data) {
200
- if (!skipSave) {
205
+ return _get(_getPrototypeOf(PersistentStore.prototype), "update", this).call(this, objects).then(function (objects) {
206
+ if (skipSave) {
207
+ var _iterator = _createForOfIteratorHelper(objects),
208
+ _step;
209
+
210
+ try {
211
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
212
+ var object = _step.value;
213
+ var type = object.getModel().getType();
214
+ _this5.models[type].storedObjects[object.getId()].fingerprint = object.getFingerprint();
215
+ }
216
+ } catch (err) {
217
+ _iterator.e(err);
218
+ } finally {
219
+ _iterator.f();
220
+ }
221
+ } else {
201
222
  _this5.delayedSave();
202
223
  }
203
224
 
204
- return data;
225
+ return objects;
205
226
  });
206
227
  }
207
228
  }]);
@@ -9,14 +9,18 @@ exports["default"] = void 0;
9
9
 
10
10
  var _ObserverStore2 = _interopRequireDefault(require("./ObserverStore"));
11
11
 
12
- var _this = void 0;
13
-
14
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
13
 
16
14
  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
15
 
18
16
  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
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
+
20
24
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21
25
 
22
26
  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); } }
@@ -41,43 +45,19 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
41
45
 
42
46
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
43
47
 
44
- function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
45
-
46
- function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
47
-
48
- 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; } } }; }
49
-
50
- 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); }
51
-
52
- 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; }
48
+ function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
53
49
 
54
- var addSubscriptionToContext = function addSubscriptionToContext(context, subKey) {
55
- // I know...
56
- context.___obs_subkeys = context.___obs_subkeys || [];
50
+ function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
57
51
 
58
- context.___obs_subkeys.push(subKey);
52
+ function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
59
53
 
60
- context.___obs_unsubscribe = function () {
61
- var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
62
- _step;
54
+ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
63
55
 
64
- try {
65
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
66
- var key = _step.value;
56
+ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
67
57
 
68
- _this.unsubscribe(key);
69
- }
70
- } catch (err) {
71
- _iterator.e(err);
72
- } finally {
73
- _iterator.f();
74
- }
75
- };
58
+ function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
76
59
 
77
- context.componentWillUnmount = function () {
78
- context.___obs_unsubscribe();
79
- };
80
- };
60
+ var _addSubscriptionToContext = /*#__PURE__*/new WeakMap();
81
61
 
82
62
  var _fixState = /*#__PURE__*/new WeakSet();
83
63
 
@@ -87,22 +67,57 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
87
67
  var _super = _createSuper(ReactStore);
88
68
 
89
69
  function ReactStore(options) {
90
- var _this2;
70
+ var _this;
91
71
 
92
72
  _classCallCheck(this, ReactStore);
93
73
 
94
- _this2 = _super.call(this, options);
74
+ _this = _super.call(this, options);
75
+
76
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this), _fixState);
77
+
78
+ _classPrivateFieldInitSpec(_assertThisInitialized(_this), _addSubscriptionToContext, {
79
+ writable: true,
80
+ value: function value(context, subKey) {
81
+ // I know...
82
+ context.___obs_subkeys = context.___obs_subkeys || [];
83
+
84
+ context.___obs_subkeys.push(subKey);
85
+
86
+ context.___obs_unsubscribe_context = _assertThisInitialized(_this);
95
87
 
96
- _classPrivateMethodInitSpec(_assertThisInitialized(_this2), _fixState);
88
+ context.___obs_unsubscribe = function () {
89
+ var _iterator = _createForOfIteratorHelper(context.___obs_subkeys || []),
90
+ _step;
97
91
 
98
- _defineProperty(_assertThisInitialized(_this2), "handleChange", function (object, name) {
92
+ try {
93
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
94
+ var key = _step.value;
95
+
96
+ context.___obs_unsubscribe_context.unsubscribe(key);
97
+ }
98
+ } catch (err) {
99
+ _iterator.e(err);
100
+ } finally {
101
+ _iterator.f();
102
+ }
103
+ };
104
+
105
+ context.componentWillUnmount = function () {
106
+ context.___obs_unsubscribe();
107
+ };
108
+ }
109
+ });
110
+
111
+ _defineProperty(_assertThisInitialized(_this), "handleChange", function (object, name) {
99
112
  return function (event, rawValue) {
113
+ var _ref;
114
+
100
115
  var value = event ? event.target.type === "checkbox" ? event.target.checked : event.target.value : "";
101
- object.set(name, value || rawValue || "");
116
+ object.set(name, (_ref = value !== null && value !== void 0 ? value : rawValue) !== null && _ref !== void 0 ? _ref : "");
102
117
  };
103
118
  });
104
119
 
105
- return _this2;
120
+ return _this;
106
121
  }
107
122
 
108
123
  _createClass(ReactStore, [{
@@ -113,7 +128,8 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
113
128
  var subKey = this.subscribe(type, function (data) {
114
129
  context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data || [])));
115
130
  }, filterFunction);
116
- addSubscriptionToContext(context, subKey);
131
+
132
+ _classPrivateFieldGet(this, _addSubscriptionToContext).call(this, context, subKey);
117
133
  }
118
134
  }, {
119
135
  key: "findOne",
@@ -123,7 +139,8 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
123
139
  var subKey = this.subscribe(type, function (data) {
124
140
  context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data && data.length ? data[0] : null)));
125
141
  }, filterFunction);
126
- addSubscriptionToContext(context, subKey);
142
+
143
+ _classPrivateFieldGet(this, _addSubscriptionToContext).call(this, context, subKey);
127
144
  }
128
145
  }]);
129
146
 
package/dist/Store.js CHANGED
@@ -29,6 +29,8 @@ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclarati
29
29
 
30
30
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
31
31
 
32
+ 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
+
32
34
  function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
33
35
 
34
36
  function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
@@ -67,6 +69,10 @@ var Store = /*#__PURE__*/function () {
67
69
 
68
70
  _classPrivateMethodInitSpec(this, _error);
69
71
 
72
+ _defineProperty(this, "getModels", function () {
73
+ return Object.keys(_this.models);
74
+ });
75
+
70
76
  _classPrivateFieldInitSpec(this, _deleteByObject, {
71
77
  writable: true,
72
78
  value: function value(object) {
@@ -255,6 +261,11 @@ var Store = /*#__PURE__*/function () {
255
261
  var obj = this.models[type].storedObjects[object.getId()];
256
262
  return obj.fingerprint !== obj.object.getFingerprint();
257
263
  }
264
+ }, {
265
+ key: "preload",
266
+ value: function preload(type) {
267
+ return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type);
268
+ }
258
269
  }, {
259
270
  key: "getDiff",
260
271
  value: function getDiff(type) {
package/dist/SubObj.js CHANGED
@@ -9,10 +9,6 @@ exports["default"] = void 0;
9
9
 
10
10
  var _BasicObj2 = require("./BasicObj");
11
11
 
12
- var _moment = _interopRequireDefault(require("moment/moment"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
12
  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); } }
17
13
 
18
14
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -22,14 +22,14 @@ var CRC32 = require('crc-32');
22
22
  var _getFingerprint = function _getFingerprint(object) {
23
23
  switch (_typeof(object)) {
24
24
  case "object":
25
- if (object._isAMomentObject) {
25
+ if (object == null) {
26
+ return "o:null";
27
+ } else if (object._isAMomentObject) {
26
28
  return "m:".concat(object.toISOString());
27
29
  } else if (object instanceof Date) {
28
30
  return "m:".concat((0, _moment["default"])(object).toISOString());
29
- } else if (object !== null) {
30
- return "o:".concat(getObjectFingerprint(object));
31
31
  } else {
32
- return "o:null";
32
+ return "o:".concat(getObjectFingerprint(object));
33
33
  }
34
34
 
35
35
  case "boolean":
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataflux",
3
- "version": "1.5.4",
3
+ "version": "1.6.2",
4
4
  "description": "DataFlux, automatically interfaces with your REST APIs to create a 2-way-synced local data store. Transparently manages data propagation in the React state.",
5
5
  "main": "dist/index.js",
6
6
  "bin": "dist/index.js",
@@ -77,16 +77,16 @@
77
77
  }
78
78
  },
79
79
  "devDependencies": {
80
- "@babel/cli": "^7.16.8",
81
- "@babel/core": "^7.16.12",
80
+ "@babel/cli": "^7.17.0",
81
+ "@babel/core": "^7.17.0",
82
82
  "@babel/node": "^7.16.8",
83
83
  "@babel/plugin-proposal-class-properties": "^7.16.7",
84
84
  "@babel/plugin-proposal-object-rest-spread": "^7.16.7",
85
85
  "@babel/plugin-transform-async-to-generator": "^7.16.8",
86
- "@babel/plugin-transform-runtime": "^7.16.10",
86
+ "@babel/plugin-transform-runtime": "^7.17.0",
87
87
  "@babel/preset-env": "^7.16.11",
88
88
  "@babel/preset-react": "^7.16.7",
89
- "chai": "^4.3.4",
89
+ "chai": "^4.3.6",
90
90
  "chai-subset": "^1.6.0",
91
91
  "dotenv-cli": "^4.1.1",
92
92
  "mocha": "^9.2.0",
@@ -96,7 +96,7 @@
96
96
  "axios": "^0.25.0",
97
97
  "batch-promises": "^0.0.3",
98
98
  "brembo": "^2.0.6",
99
- "crc-32": "^1.2.0",
99
+ "crc-32": "^1.2.1",
100
100
  "moment": "^2.29.1",
101
101
  "uuid": "^8.3.2"
102
102
  },