@faasjs/react 0.0.4-beta.14 → 0.0.4-beta.16
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/index.js +57 -69
- package/dist/index.mjs +57 -69
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -41,66 +41,60 @@ function FaasReactClient({
|
|
|
41
41
|
}, [
|
|
42
42
|
typeof options2.skip === "function" ? JSON.stringify(params) : options2.skip
|
|
43
43
|
]);
|
|
44
|
-
react.useEffect(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
44
|
+
react.useEffect(() => {
|
|
45
|
+
if (JSON.stringify(defaultParams) !== JSON.stringify(params)) {
|
|
46
|
+
setParams(defaultParams);
|
|
47
|
+
}
|
|
48
|
+
}, [JSON.stringify(defaultParams)]);
|
|
49
|
+
react.useEffect(() => {
|
|
50
|
+
if (!action || skip) {
|
|
51
|
+
setLoading(false);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setLoading(true);
|
|
55
|
+
const controller = new AbortController();
|
|
56
|
+
function send() {
|
|
57
|
+
const request = client.action(
|
|
58
|
+
action,
|
|
59
|
+
options2.params || params,
|
|
60
|
+
{ signal: controller.signal }
|
|
61
|
+
);
|
|
62
|
+
setPromise(request);
|
|
63
|
+
request.then(
|
|
64
|
+
(r) => (options2 == null ? void 0 : options2.setData) ? options2.setData(r.data) : setData(r.data)
|
|
65
|
+
).catch(async (e) => {
|
|
66
|
+
if ((e == null ? void 0 : e.message) === "The user aborted a request." || (e == null ? void 0 : e.message) === "Aborted")
|
|
67
|
+
return;
|
|
68
|
+
if (!fails && typeof (e == null ? void 0 : e.message) === "string" && e.message.indexOf("Failed to fetch") >= 0) {
|
|
69
|
+
console.warn(`FaasReactClient: ${e.message} retry...`);
|
|
70
|
+
setFails(1);
|
|
71
|
+
return send();
|
|
72
|
+
}
|
|
73
|
+
if (onError)
|
|
74
|
+
try {
|
|
75
|
+
await onError(action, params)(e);
|
|
76
|
+
} catch (error2) {
|
|
77
|
+
setError(error2);
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
setError(e);
|
|
85
|
-
return Promise.reject(e);
|
|
86
|
-
}).finally(() => setLoading(false));
|
|
87
|
-
}
|
|
88
|
-
if (options2 == null ? void 0 : options2.debounce) {
|
|
89
|
-
const timeout = setTimeout(send, options2.debounce);
|
|
90
|
-
return () => {
|
|
91
|
-
clearTimeout(timeout);
|
|
92
|
-
controller.abort();
|
|
93
|
-
setLoading(false);
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
send();
|
|
79
|
+
else
|
|
80
|
+
setError(e);
|
|
81
|
+
return Promise.reject(e);
|
|
82
|
+
}).finally(() => setLoading(false));
|
|
83
|
+
}
|
|
84
|
+
if (options2 == null ? void 0 : options2.debounce) {
|
|
85
|
+
const timeout = setTimeout(send, options2.debounce);
|
|
97
86
|
return () => {
|
|
87
|
+
clearTimeout(timeout);
|
|
98
88
|
controller.abort();
|
|
99
89
|
setLoading(false);
|
|
100
90
|
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
}
|
|
92
|
+
send();
|
|
93
|
+
return () => {
|
|
94
|
+
controller.abort();
|
|
95
|
+
setLoading(false);
|
|
96
|
+
};
|
|
97
|
+
}, [action, JSON.stringify(options2.params || params), reloadTimes, skip]);
|
|
104
98
|
return {
|
|
105
99
|
action,
|
|
106
100
|
params,
|
|
@@ -140,20 +134,14 @@ function FaasReactClient({
|
|
|
140
134
|
setData
|
|
141
135
|
});
|
|
142
136
|
const [loaded, setLoaded] = react.useState(false);
|
|
143
|
-
react.useEffect(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
function() {
|
|
152
|
-
if (onDataChange)
|
|
153
|
-
onDataChange(request);
|
|
154
|
-
},
|
|
155
|
-
[JSON.stringify(request.data)]
|
|
156
|
-
);
|
|
137
|
+
react.useEffect(() => {
|
|
138
|
+
if (!loaded && !request.loading)
|
|
139
|
+
setLoaded(true);
|
|
140
|
+
}, [request.loading]);
|
|
141
|
+
react.useEffect(() => {
|
|
142
|
+
if (onDataChange)
|
|
143
|
+
onDataChange(request);
|
|
144
|
+
}, [JSON.stringify(request.data)]);
|
|
157
145
|
if (loaded) {
|
|
158
146
|
if (children)
|
|
159
147
|
return react.cloneElement(children, request);
|
package/dist/index.mjs
CHANGED
|
@@ -40,66 +40,60 @@ function FaasReactClient({
|
|
|
40
40
|
}, [
|
|
41
41
|
typeof options2.skip === "function" ? JSON.stringify(params) : options2.skip
|
|
42
42
|
]);
|
|
43
|
-
useEffect(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (JSON.stringify(defaultParams) !== JSON.stringify(params)) {
|
|
45
|
+
setParams(defaultParams);
|
|
46
|
+
}
|
|
47
|
+
}, [JSON.stringify(defaultParams)]);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!action || skip) {
|
|
50
|
+
setLoading(false);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
setLoading(true);
|
|
54
|
+
const controller = new AbortController();
|
|
55
|
+
function send() {
|
|
56
|
+
const request = client.action(
|
|
57
|
+
action,
|
|
58
|
+
options2.params || params,
|
|
59
|
+
{ signal: controller.signal }
|
|
60
|
+
);
|
|
61
|
+
setPromise(request);
|
|
62
|
+
request.then(
|
|
63
|
+
(r) => (options2 == null ? void 0 : options2.setData) ? options2.setData(r.data) : setData(r.data)
|
|
64
|
+
).catch(async (e) => {
|
|
65
|
+
if ((e == null ? void 0 : e.message) === "The user aborted a request." || (e == null ? void 0 : e.message) === "Aborted")
|
|
66
|
+
return;
|
|
67
|
+
if (!fails && typeof (e == null ? void 0 : e.message) === "string" && e.message.indexOf("Failed to fetch") >= 0) {
|
|
68
|
+
console.warn(`FaasReactClient: ${e.message} retry...`);
|
|
69
|
+
setFails(1);
|
|
70
|
+
return send();
|
|
71
|
+
}
|
|
72
|
+
if (onError)
|
|
73
|
+
try {
|
|
74
|
+
await onError(action, params)(e);
|
|
75
|
+
} catch (error2) {
|
|
76
|
+
setError(error2);
|
|
75
77
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
setError(e);
|
|
84
|
-
return Promise.reject(e);
|
|
85
|
-
}).finally(() => setLoading(false));
|
|
86
|
-
}
|
|
87
|
-
if (options2 == null ? void 0 : options2.debounce) {
|
|
88
|
-
const timeout = setTimeout(send, options2.debounce);
|
|
89
|
-
return () => {
|
|
90
|
-
clearTimeout(timeout);
|
|
91
|
-
controller.abort();
|
|
92
|
-
setLoading(false);
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
send();
|
|
78
|
+
else
|
|
79
|
+
setError(e);
|
|
80
|
+
return Promise.reject(e);
|
|
81
|
+
}).finally(() => setLoading(false));
|
|
82
|
+
}
|
|
83
|
+
if (options2 == null ? void 0 : options2.debounce) {
|
|
84
|
+
const timeout = setTimeout(send, options2.debounce);
|
|
96
85
|
return () => {
|
|
86
|
+
clearTimeout(timeout);
|
|
97
87
|
controller.abort();
|
|
98
88
|
setLoading(false);
|
|
99
89
|
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
}
|
|
91
|
+
send();
|
|
92
|
+
return () => {
|
|
93
|
+
controller.abort();
|
|
94
|
+
setLoading(false);
|
|
95
|
+
};
|
|
96
|
+
}, [action, JSON.stringify(options2.params || params), reloadTimes, skip]);
|
|
103
97
|
return {
|
|
104
98
|
action,
|
|
105
99
|
params,
|
|
@@ -139,20 +133,14 @@ function FaasReactClient({
|
|
|
139
133
|
setData
|
|
140
134
|
});
|
|
141
135
|
const [loaded, setLoaded] = useState(false);
|
|
142
|
-
useEffect(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
function() {
|
|
151
|
-
if (onDataChange)
|
|
152
|
-
onDataChange(request);
|
|
153
|
-
},
|
|
154
|
-
[JSON.stringify(request.data)]
|
|
155
|
-
);
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (!loaded && !request.loading)
|
|
138
|
+
setLoaded(true);
|
|
139
|
+
}, [request.loading]);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
if (onDataChange)
|
|
142
|
+
onDataChange(request);
|
|
143
|
+
}, [JSON.stringify(request.data)]);
|
|
156
144
|
if (loaded) {
|
|
157
145
|
if (children)
|
|
158
146
|
return cloneElement(children, request);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/react",
|
|
3
|
-
"version": "0.0.4-beta.
|
|
3
|
+
"version": "0.0.4-beta.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@faasjs/browser": "0.0.4-beta.
|
|
25
|
+
"@faasjs/browser": "0.0.4-beta.16"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "*",
|