dataflux 1.7.0 → 1.7.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/README.md +8 -4
- package/dist/modelHooksUtils.js +18 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -392,10 +392,14 @@ To create a factory, you must declare a model as follows:
|
|
|
392
392
|
```js
|
|
393
393
|
const author = new Model("author", {
|
|
394
394
|
lazyLoad: true, // It MUST be lazyLoaded
|
|
395
|
-
retrieve: (
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
395
|
+
retrieve: (params) => { // The retrieve function now takes some parameters
|
|
396
|
+
|
|
397
|
+
if (params) {
|
|
398
|
+
// You can return a URL or directly one or more JSON objects
|
|
399
|
+
return `https://api.example.net/authors/${params.id}`
|
|
400
|
+
} else {
|
|
401
|
+
return Promise.resolve([]); // It's important to handle the base case where params is null
|
|
402
|
+
}
|
|
399
403
|
}
|
|
400
404
|
});
|
|
401
405
|
|
package/dist/modelHooksUtils.js
CHANGED
|
@@ -65,7 +65,18 @@ var createHookItem = function createHookItem(optionItem, defaultMethod, defaultU
|
|
|
65
65
|
|
|
66
66
|
case "function":
|
|
67
67
|
return function (data) {
|
|
68
|
-
|
|
68
|
+
var res = optionItem(data);
|
|
69
|
+
|
|
70
|
+
if (typeof res === "string") {
|
|
71
|
+
return {
|
|
72
|
+
method: defaultMethod,
|
|
73
|
+
url: res,
|
|
74
|
+
fields: options.fields || [],
|
|
75
|
+
headers: options.headers || {}
|
|
76
|
+
};
|
|
77
|
+
} else {
|
|
78
|
+
return Promise.resolve(res);
|
|
79
|
+
}
|
|
69
80
|
};
|
|
70
81
|
|
|
71
82
|
case "object":
|
|
@@ -115,7 +126,12 @@ var executeHook = function executeHook(type, hook, data, axios) {
|
|
|
115
126
|
|
|
116
127
|
case "function":
|
|
117
128
|
var res = hook(data);
|
|
118
|
-
|
|
129
|
+
|
|
130
|
+
if (res.method && res.url && res.headers) {
|
|
131
|
+
return getDataStringHook(res, data, axios);
|
|
132
|
+
} else {
|
|
133
|
+
return res;
|
|
134
|
+
}
|
|
119
135
|
|
|
120
136
|
default:
|
|
121
137
|
return Promise.reject("The ".concat(type, " hook must be a URL or a function returning a promise"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dataflux",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.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",
|