dataflux 1.2.2 → 1.2.3
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/dist/Model.js +29 -27
- package/dist/StoreObject.js +8 -4
- package/package.json +1 -1
package/dist/Model.js
CHANGED
|
@@ -49,6 +49,18 @@ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!priva
|
|
|
49
49
|
|
|
50
50
|
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; } }
|
|
51
51
|
|
|
52
|
+
var applyData = function applyData(obj, data) {
|
|
53
|
+
for (var att in data) {
|
|
54
|
+
if (att !== "id" || obj.id === undefined || att === "id" && obj.id === data.id) {
|
|
55
|
+
obj[att] = data[att];
|
|
56
|
+
} else {
|
|
57
|
+
return Promise.reject("The loading function cannot change the id of the object.");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return Promise.resolve(obj);
|
|
62
|
+
};
|
|
63
|
+
|
|
52
64
|
var _type = /*#__PURE__*/new WeakMap();
|
|
53
65
|
|
|
54
66
|
var _store = /*#__PURE__*/new WeakMap();
|
|
@@ -160,35 +172,25 @@ var Model = /*#__PURE__*/_createClass(function Model(name) {
|
|
|
160
172
|
});
|
|
161
173
|
|
|
162
174
|
_defineProperty(this, "load", function (obj) {
|
|
163
|
-
|
|
164
|
-
var
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (_classPrivateFieldGet(_this, _loadFunction)) {
|
|
175
|
-
var res = _classPrivateFieldGet(_this, _loadFunction).call(_this, obj.toJSON());
|
|
176
|
-
|
|
177
|
-
if (typeof res === "string") {
|
|
178
|
-
_classPrivateFieldGet(_this, _axios).call(_this, {
|
|
179
|
-
method: "get",
|
|
180
|
-
url: res,
|
|
181
|
-
responseType: "json"
|
|
182
|
-
}).then(function (data) {
|
|
183
|
-
return applyData(data.data);
|
|
184
|
-
}).then(resolve);
|
|
185
|
-
} else {
|
|
186
|
-
res.then(applyData).then(resolve);
|
|
187
|
-
}
|
|
175
|
+
if (_classPrivateFieldGet(_this, _loadFunction)) {
|
|
176
|
+
var res = _classPrivateFieldGet(_this, _loadFunction).call(_this, obj.toJSON());
|
|
177
|
+
|
|
178
|
+
if (typeof res === "string") {
|
|
179
|
+
return _classPrivateFieldGet(_this, _axios).call(_this, {
|
|
180
|
+
method: "get",
|
|
181
|
+
url: res,
|
|
182
|
+
responseType: "json"
|
|
183
|
+
}).then(function (data) {
|
|
184
|
+
return applyData(obj, data.data);
|
|
185
|
+
});
|
|
188
186
|
} else {
|
|
189
|
-
|
|
187
|
+
return res.then(function (data) {
|
|
188
|
+
return applyData(obj, data);
|
|
189
|
+
});
|
|
190
190
|
}
|
|
191
|
-
}
|
|
191
|
+
} else {
|
|
192
|
+
return Promise.reject("You must define a loading function in the model to enable load().");
|
|
193
|
+
}
|
|
192
194
|
});
|
|
193
195
|
|
|
194
196
|
_defineProperty(this, "addRelation", function (model, param2, param3) {
|
package/dist/StoreObject.js
CHANGED
|
@@ -35,7 +35,7 @@ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) {
|
|
|
35
35
|
|
|
36
36
|
var _loaded = /*#__PURE__*/new WeakMap();
|
|
37
37
|
|
|
38
|
-
var Obj = /*#__PURE__*/_createClass(function Obj(values,
|
|
38
|
+
var Obj = /*#__PURE__*/_createClass(function Obj(values, _model) {
|
|
39
39
|
var _this = this;
|
|
40
40
|
|
|
41
41
|
_classCallCheck(this, Obj);
|
|
@@ -49,11 +49,15 @@ var Obj = /*#__PURE__*/_createClass(function Obj(values, model) {
|
|
|
49
49
|
if (_classPrivateFieldGet(_this, _loaded)) {
|
|
50
50
|
return Promise.resolve(_this);
|
|
51
51
|
} else {
|
|
52
|
-
|
|
52
|
+
var model = _this.getModel();
|
|
53
|
+
|
|
54
|
+
return model.load(_this).then(function () {
|
|
53
55
|
_classPrivateFieldSet(_this, _loaded, true);
|
|
54
56
|
|
|
57
|
+
return model.getStore().update([_this]); // Propagate update
|
|
58
|
+
}).then(function () {
|
|
55
59
|
return _this;
|
|
56
|
-
});
|
|
60
|
+
}); // return always this
|
|
57
61
|
}
|
|
58
62
|
});
|
|
59
63
|
|
|
@@ -107,7 +111,7 @@ var Obj = /*#__PURE__*/_createClass(function Obj(values, model) {
|
|
|
107
111
|
});
|
|
108
112
|
|
|
109
113
|
this.getModel = function () {
|
|
110
|
-
return
|
|
114
|
+
return _model;
|
|
111
115
|
};
|
|
112
116
|
|
|
113
117
|
Object.keys(values).forEach(function (key) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataflux",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
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",
|