dataflux 1.1.1 → 1.1.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.
@@ -39,6 +39,12 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
39
39
 
40
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
41
 
42
+ function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
43
+
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
+
42
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; } } }; }
43
49
 
44
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); }
@@ -73,6 +79,8 @@ var addSubscriptionToContext = function addSubscriptionToContext(context, subKey
73
79
  };
74
80
  };
75
81
 
82
+ var _fixState = /*#__PURE__*/new WeakSet();
83
+
76
84
  var ReactStore = /*#__PURE__*/function (_ObserverStore) {
77
85
  _inherits(ReactStore, _ObserverStore);
78
86
 
@@ -85,6 +93,8 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
85
93
 
86
94
  _this2 = _super.call(this, options);
87
95
 
96
+ _classPrivateMethodInitSpec(_assertThisInitialized(_this2), _fixState);
97
+
88
98
  _defineProperty(_assertThisInitialized(_this2), "handleChange", function (object, name) {
89
99
  return function (event, rawValue) {
90
100
  var value = event ? event.target.type === "checkbox" ? event.target.checked : event.target.value : "";
@@ -98,14 +108,18 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
98
108
  _createClass(ReactStore, [{
99
109
  key: "findAll",
100
110
  value: function findAll(type, stateAttribute, context, filterFunction) {
111
+ _classPrivateMethodGet(this, _fixState, _fixState2).call(this, stateAttribute, context);
112
+
101
113
  var subKey = this.subscribe(type, function (data) {
102
- context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data)));
114
+ context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data || [])));
103
115
  }, filterFunction);
104
116
  addSubscriptionToContext(context, subKey);
105
117
  }
106
118
  }, {
107
119
  key: "findOne",
108
120
  value: function findOne(type, stateAttribute, context, filterFunction) {
121
+ _classPrivateMethodGet(this, _fixState, _fixState2).call(this, stateAttribute, context);
122
+
109
123
  var subKey = this.subscribe(type, function (data) {
110
124
  context.setState(_objectSpread(_objectSpread({}, context.state), {}, _defineProperty({}, stateAttribute, data && data.length ? data[0] : null)));
111
125
  }, filterFunction);
@@ -116,4 +130,10 @@ var ReactStore = /*#__PURE__*/function (_ObserverStore) {
116
130
  return ReactStore;
117
131
  }(_ObserverStore2["default"]);
118
132
 
119
- exports["default"] = ReactStore;
133
+ exports["default"] = ReactStore;
134
+
135
+ function _fixState2(stateAttribute, context) {
136
+ if (!context[stateAttribute]) {
137
+ context[stateAttribute] = []; // side effect on state
138
+ }
139
+ }
package/dist/Store.js CHANGED
@@ -159,6 +159,10 @@ var Store = /*#__PURE__*/function () {
159
159
  return i.object;
160
160
  });
161
161
  return filterFunction ? all.filter(filterFunction) : all;
162
+ })["catch"](function (error) {
163
+ _this4.pubSub.publish("error", error);
164
+
165
+ return Promise.reject(error);
162
166
  });
163
167
  }
164
168
  }, {
@@ -320,6 +324,10 @@ function _loadObjects2(type) {
320
324
  var _this9 = this;
321
325
 
322
326
  var item = this.models[type];
327
+ this.pubSub.publish("loading", {
328
+ status: "start",
329
+ model: type
330
+ });
323
331
  return item.promise = item.model.retrieveAll().then(function (items) {
324
332
  var _iterator4 = _createForOfIteratorHelper(items),
325
333
  _step4;
@@ -335,5 +343,10 @@ function _loadObjects2(type) {
335
343
  } finally {
336
344
  _iterator4.f();
337
345
  }
346
+
347
+ _this9.pubSub.publish("loading", {
348
+ status: "end",
349
+ model: type
350
+ });
338
351
  });
339
352
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dataflux",
3
- "version": "1.1.1",
3
+ "version": "1.1.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",