dataflux 1.10.4 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/BasicObj.js +0 -53
- package/dist/Model.js +24 -148
- package/dist/Obj.js +0 -47
- package/dist/ObserverStore.js +16 -129
- package/dist/PersistentStore.js +10 -61
- package/dist/PubSub.js +1 -17
- package/dist/ReactStore.js +1 -52
- package/dist/Store.js +51 -148
- package/dist/SubObj.js +0 -45
- package/dist/dataflux.min.js +1 -1
- package/dist/dataflux.min.js.map +1 -1
- package/dist/fingerprint.js +1 -19
- package/dist/index.js +0 -3
- package/dist/modelHooksUtils.js +0 -28
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -568,6 +568,8 @@ The store has the following method.
|
|
|
568
568
|
| save() | Persist the changes. Edited local objects will be sent to the REST APIs (insert/update/delete). See also [editing objects](#editing-objects). |
|
|
569
569
|
| save() | Persist the changes (`local -> remote`). Edited local objects will be sent to the REST APIs (insert/update/delete). See also [editing objects](#editing-objects). |
|
|
570
570
|
| refresh() | This method syncs all the objects in the store with the remote version offered by the REST APIs (`remote -> local`). Remote changes are applied locally, including adding/removing objects. Objects edited locally but not yet persisted are preserved locally (tip: you can also create a store with the `autoRefresh` option). |
|
|
571
|
+
| findSync(type, filterFunction) | This method returns the objects in a synchronous way (no Promise). However, *it works only if you already performed an async operation (e.g., like refresh, load, find, subscribe) or if you set lazyLoad to false and the store had enough time to load.* |
|
|
572
|
+
|
|
571
573
|
### Insert vs. Mock
|
|
572
574
|
|
|
573
575
|
If you do:
|
package/dist/BasicObj.js
CHANGED
|
@@ -5,45 +5,27 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.dateRegex = exports.BasicObj = void 0;
|
|
7
7
|
exports.setValues = setValues;
|
|
8
|
-
|
|
9
8
|
var _moment = _interopRequireDefault(require("moment/moment"));
|
|
10
|
-
|
|
11
9
|
var _uuid = require("uuid");
|
|
12
|
-
|
|
13
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
14
|
-
|
|
15
11
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
-
|
|
17
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); } }
|
|
18
|
-
|
|
19
13
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
20
|
-
|
|
21
14
|
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; }
|
|
22
|
-
|
|
23
15
|
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
24
|
-
|
|
25
16
|
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
26
|
-
|
|
27
17
|
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
28
|
-
|
|
29
18
|
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
30
|
-
|
|
31
19
|
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
32
|
-
|
|
33
20
|
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
34
|
-
|
|
35
21
|
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
36
|
-
|
|
37
22
|
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
|
-
|
|
39
23
|
var dateRegex = new RegExp("^[0-9][0-9][0-9][0-9]-[0-9].*T[0-9].*Z$");
|
|
40
24
|
exports.dateRegex = dateRegex;
|
|
41
25
|
var globalError = "_object";
|
|
42
|
-
|
|
43
26
|
function setValues(values, model, SubObj, parent, context) {
|
|
44
27
|
Object.keys(values).forEach(function (key) {
|
|
45
28
|
var value = values[key];
|
|
46
|
-
|
|
47
29
|
if (model.options.parseMoment && value != null && dateRegex.test(value)) {
|
|
48
30
|
var mmnt = (0, _moment["default"])(value);
|
|
49
31
|
context[key] = mmnt.isValid() ? mmnt : value;
|
|
@@ -60,76 +42,56 @@ function setValues(values, model, SubObj, parent, context) {
|
|
|
60
42
|
}
|
|
61
43
|
});
|
|
62
44
|
}
|
|
63
|
-
|
|
64
45
|
var _setHidden = /*#__PURE__*/new WeakMap();
|
|
65
|
-
|
|
66
46
|
var _id = /*#__PURE__*/new WeakMap();
|
|
67
|
-
|
|
68
47
|
var _error = /*#__PURE__*/new WeakMap();
|
|
69
|
-
|
|
70
48
|
var _model = /*#__PURE__*/new WeakMap();
|
|
71
|
-
|
|
72
49
|
var BasicObj = /*#__PURE__*/function () {
|
|
73
50
|
function BasicObj(values, model) {
|
|
74
51
|
var _this = this;
|
|
75
|
-
|
|
76
52
|
_classCallCheck(this, BasicObj);
|
|
77
|
-
|
|
78
53
|
_classPrivateFieldInitSpec(this, _setHidden, {
|
|
79
54
|
writable: true,
|
|
80
55
|
value: {}
|
|
81
56
|
});
|
|
82
|
-
|
|
83
57
|
_classPrivateFieldInitSpec(this, _id, {
|
|
84
58
|
writable: true,
|
|
85
59
|
value: null
|
|
86
60
|
});
|
|
87
|
-
|
|
88
61
|
_classPrivateFieldInitSpec(this, _error, {
|
|
89
62
|
writable: true,
|
|
90
63
|
value: {}
|
|
91
64
|
});
|
|
92
|
-
|
|
93
65
|
_classPrivateFieldInitSpec(this, _model, {
|
|
94
66
|
writable: true,
|
|
95
67
|
value: void 0
|
|
96
68
|
});
|
|
97
|
-
|
|
98
69
|
_defineProperty(this, "setId", function (id) {
|
|
99
70
|
_this.id = id;
|
|
100
71
|
});
|
|
101
|
-
|
|
102
72
|
_defineProperty(this, "getId", function () {
|
|
103
73
|
if (!_classPrivateFieldGet(_this, _id)) {
|
|
104
74
|
if (_this.id != null && (typeof _this.id === "string" || typeof _this.id === "number")) {
|
|
105
75
|
_classPrivateFieldSet(_this, _id, _this.id.toString());
|
|
106
|
-
|
|
107
76
|
delete _this.setId;
|
|
108
77
|
} else {
|
|
109
78
|
_classPrivateFieldSet(_this, _id, (0, _uuid.v4)());
|
|
110
79
|
}
|
|
111
80
|
}
|
|
112
|
-
|
|
113
81
|
return _classPrivateFieldGet(_this, _id);
|
|
114
82
|
});
|
|
115
|
-
|
|
116
83
|
_defineProperty(this, "get", function (attribute, defaultValue) {
|
|
117
84
|
var _ref, _classPrivateFieldGet2;
|
|
118
|
-
|
|
119
85
|
return (_ref = (_classPrivateFieldGet2 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet2 !== void 0 ? _classPrivateFieldGet2 : _this[attribute]) !== null && _ref !== void 0 ? _ref : defaultValue;
|
|
120
86
|
});
|
|
121
|
-
|
|
122
87
|
_defineProperty(this, "getError", function () {
|
|
123
88
|
var _classPrivateFieldGet3;
|
|
124
|
-
|
|
125
89
|
var attribute = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
126
90
|
var key = attribute ? attribute : globalError;
|
|
127
91
|
return (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _error)[key]) !== null && _classPrivateFieldGet3 !== void 0 ? _classPrivateFieldGet3 : false;
|
|
128
92
|
});
|
|
129
|
-
|
|
130
93
|
_defineProperty(this, "setError", function (error) {
|
|
131
94
|
var attribute = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
132
|
-
|
|
133
95
|
if (error && attribute) {
|
|
134
96
|
_classPrivateFieldGet(_this, _error)[attribute] = error;
|
|
135
97
|
} else if (error && !attribute) {
|
|
@@ -140,20 +102,15 @@ var BasicObj = /*#__PURE__*/function () {
|
|
|
140
102
|
_classPrivateFieldSet(_this, _error, {});
|
|
141
103
|
}
|
|
142
104
|
});
|
|
143
|
-
|
|
144
105
|
_defineProperty(this, "setConstant", function (attribute, value) {
|
|
145
106
|
var _classPrivateFieldGet4;
|
|
146
|
-
|
|
147
107
|
_classPrivateFieldGet(_this, _setHidden)[attribute] = (_classPrivateFieldGet4 = _classPrivateFieldGet(_this, _setHidden)[attribute]) !== null && _classPrivateFieldGet4 !== void 0 ? _classPrivateFieldGet4 : value;
|
|
148
108
|
});
|
|
149
|
-
|
|
150
109
|
_defineProperty(this, "toJSON", function () {
|
|
151
110
|
var attrs = Object.keys(_this);
|
|
152
111
|
var out = {};
|
|
153
|
-
|
|
154
112
|
for (var _i = 0, _attrs = attrs; _i < _attrs.length; _i++) {
|
|
155
113
|
var a = _attrs[_i];
|
|
156
|
-
|
|
157
114
|
if (_this[a] == null) {
|
|
158
115
|
out[a] = _this[a];
|
|
159
116
|
} else if (_this[a] instanceof _moment["default"]) {
|
|
@@ -172,21 +129,16 @@ var BasicObj = /*#__PURE__*/function () {
|
|
|
172
129
|
out[a] = _this[a];
|
|
173
130
|
}
|
|
174
131
|
}
|
|
175
|
-
|
|
176
132
|
return out;
|
|
177
133
|
});
|
|
178
|
-
|
|
179
134
|
_defineProperty(this, "toString", function () {
|
|
180
135
|
return JSON.stringify(_this.toJSON());
|
|
181
136
|
});
|
|
182
|
-
|
|
183
137
|
_defineProperty(this, "update", function () {
|
|
184
138
|
return Promise.resolve();
|
|
185
139
|
});
|
|
186
|
-
|
|
187
140
|
_classPrivateFieldSet(this, _model, model);
|
|
188
141
|
}
|
|
189
|
-
|
|
190
142
|
_createClass(BasicObj, [{
|
|
191
143
|
key: "set",
|
|
192
144
|
value: function set(attribute, value, hidden) {
|
|
@@ -196,17 +148,12 @@ var BasicObj = /*#__PURE__*/function () {
|
|
|
196
148
|
if (attribute === "id") {
|
|
197
149
|
throw new Error("You cannot change the ID");
|
|
198
150
|
}
|
|
199
|
-
|
|
200
151
|
this[attribute] = value;
|
|
201
|
-
|
|
202
152
|
_classPrivateFieldGet(this, _model).validateObjectAttribute(this, attribute);
|
|
203
153
|
}
|
|
204
|
-
|
|
205
154
|
return this.update();
|
|
206
155
|
}
|
|
207
156
|
}]);
|
|
208
|
-
|
|
209
157
|
return BasicObj;
|
|
210
158
|
}();
|
|
211
|
-
|
|
212
159
|
exports.BasicObj = BasicObj;
|