dataflux 1.5.3 → 1.6.1

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
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.dateRegex = exports.BasicObj = void 0;
7
+ exports.setValues = setValues;
7
8
 
8
9
  var _moment = _interopRequireDefault(require("moment/moment"));
9
10
 
@@ -33,9 +34,30 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
33
34
 
34
35
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
35
36
 
37
+ 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); }
38
+
36
39
  var dateRegex = new RegExp("^[0-9][0-9][0-9][0-9]-[0-9].*T[0-9].*Z$");
37
40
  exports.dateRegex = dateRegex;
38
41
 
42
+ function setValues(values, model, SubObj, parent, context) {
43
+ Object.keys(values).forEach(function (key) {
44
+ var value = values[key];
45
+
46
+ if (model.options.parseMoment && value != null && dateRegex.test(value)) {
47
+ var mmnt = (0, _moment["default"])(value);
48
+ context[key] = mmnt.isValid() ? mmnt : value;
49
+ } else if (model.options.deep && value != null && _typeof(value) === "object" && !Array.isArray(value)) {
50
+ context[key] = new SubObj(parent, key, value, model);
51
+ } else if (model.options.deep && value != null && Array.isArray(value)) {
52
+ context[key] = value.map(function (i) {
53
+ return new SubObj(parent, key, i, model);
54
+ });
55
+ } else {
56
+ context[key] = value;
57
+ }
58
+ });
59
+ }
60
+
39
61
  var _setHidden = /*#__PURE__*/new WeakMap();
40
62
 
41
63
  var _id = /*#__PURE__*/new WeakMap();
@@ -100,14 +122,16 @@ var BasicObj = /*#__PURE__*/_createClass(function BasicObj(values, model) {
100
122
  for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
101
123
  var a = _attrs[_i];
102
124
 
103
- if (_this[a] instanceof _moment["default"]) {
125
+ if (_this[a] == null) {
126
+ out[a] = _this[a];
127
+ } else if (_this[a] instanceof _moment["default"]) {
104
128
  out[a] = _this[a].toISOString();
105
129
  } else if (_this[a] instanceof Date) {
106
130
  out[a] = (0, _moment["default"])(_this[a]).toISOString();
107
- } else if (_this[a].toJSON) {
131
+ } else if (_typeof(_this[a]) === "object" && _this[a].toJSON) {
108
132
  out[a] = _this[a].toJSON();
109
133
  } else if (Array.isArray(_this[a]) && _this[a].every(function (i) {
110
- return i.toJSON;
134
+ return _typeof(i) === "object" && i.toJSON;
111
135
  })) {
112
136
  out[a] = _this[a].map(function (i) {
113
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");
package/dist/Obj.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
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
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -7,18 +9,12 @@ exports["default"] = void 0;
7
9
 
8
10
  var _fingerprint = _interopRequireDefault(require("./fingerprint"));
9
11
 
10
- var _uuid = require("uuid");
11
-
12
12
  var _BasicObj2 = require("./BasicObj");
13
13
 
14
- var _moment = _interopRequireDefault(require("moment/moment"));
15
-
16
14
  var _SubObj = _interopRequireDefault(require("./SubObj"));
17
15
 
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
17
 
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); }
21
-
22
18
  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
19
 
24
20
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -110,22 +106,7 @@ var Obj = /*#__PURE__*/function (_BasicObj) {
110
106
  return _this.getModel().getStore().update([_assertThisInitialized(_this)]);
111
107
  });
112
108
 
113
- Object.keys(values).forEach(function (key) {
114
- var value = values[key];
115
-
116
- if (_model.options.parseMoment && _BasicObj2.dateRegex.test(value)) {
117
- var mmnt = (0, _moment["default"])(value);
118
- _this[key] = mmnt.isValid() ? mmnt : value;
119
- } else if (_model.options.deep && _typeof(value) === "object" && !Array.isArray(value)) {
120
- _this[key] = new _SubObj["default"](_assertThisInitialized(_this), key, value, _model);
121
- } else if (_model.options.deep && Array.isArray(value)) {
122
- _this[key] = value.map(function (i) {
123
- return new _SubObj["default"](_assertThisInitialized(_this), key, i, _model);
124
- });
125
- } else {
126
- _this[key] = value;
127
- }
128
- });
109
+ (0, _BasicObj2.setValues)(values, _model, _SubObj["default"], _assertThisInitialized(_this), _assertThisInitialized(_this));
129
110
 
130
111
  _this.getModel = function () {
131
112
  return _model;
@@ -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
@@ -255,6 +255,11 @@ var Store = /*#__PURE__*/function () {
255
255
  var obj = this.models[type].storedObjects[object.getId()];
256
256
  return obj.fingerprint !== obj.object.getFingerprint();
257
257
  }
258
+ }, {
259
+ key: "preload",
260
+ value: function preload(type) {
261
+ return _classPrivateMethodGet(this, _getPromise, _getPromise2).call(this, type);
262
+ }
258
263
  }, {
259
264
  key: "getDiff",
260
265
  value: function getDiff(type) {
package/dist/SubObj.js CHANGED
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
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
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -7,12 +9,6 @@ exports["default"] = void 0;
7
9
 
8
10
  var _BasicObj2 = require("./BasicObj");
9
11
 
10
- var _moment = _interopRequireDefault(require("moment/moment"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
- 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); }
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; }
@@ -110,22 +106,7 @@ var SubObj = /*#__PURE__*/function (_BasicObj) {
110
106
 
111
107
  _classPrivateFieldSet(_assertThisInitialized(_this), _parentField, field);
112
108
 
113
- Object.keys(values).forEach(function (key) {
114
- var value = values[key];
115
-
116
- if (model.options.parseMoment && _BasicObj2.dateRegex.test(value)) {
117
- var mmnt = (0, _moment["default"])(value);
118
- _this[key] = mmnt.isValid() ? mmnt : value;
119
- } else if (model.options.deep && _typeof(value) === "object" && !Array.isArray(value)) {
120
- _this[key] = new SubObj(_classPrivateFieldGet(_assertThisInitialized(_this), _parent), key, value, model);
121
- } else if (model.options.deep && Array.isArray(value)) {
122
- _this[key] = value.map(function (i) {
123
- return new SubObj(_classPrivateFieldGet(_assertThisInitialized(_this), _parent), key, i, model);
124
- });
125
- } else {
126
- _this[key] = value;
127
- }
128
- });
109
+ (0, _BasicObj2.setValues)(values, model, SubObj, _classPrivateFieldGet(_assertThisInitialized(_this), _parent), _assertThisInitialized(_this));
129
110
  return _this;
130
111
  }
131
112
 
@@ -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.3",
3
+ "version": "1.6.1",
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
  },