@faasjs/react 0.0.4-beta.15 → 0.0.4-beta.17
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 +26 -4
- package/dist/index.d.mts +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +57 -69
- package/dist/index.mjs +57 -69
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ React plugin for FaasJS.
|
|
|
33
33
|
- [FaasDataWrapperProps](#faasdatawrapperprops)
|
|
34
34
|
- [FaasParams](#faasparams)
|
|
35
35
|
- [FaasReactClientInstance](#faasreactclientinstance)
|
|
36
|
+
- [FaasReactClientOptions](#faasreactclientoptions)
|
|
36
37
|
- [Options](#options)
|
|
37
38
|
- [ResponseHeaders](#responseheaders)
|
|
38
39
|
- [SignalOptions](#signaloptions)
|
|
@@ -165,6 +166,20 @@ ___
|
|
|
165
166
|
|
|
166
167
|
___
|
|
167
168
|
|
|
169
|
+
### FaasReactClientOptions
|
|
170
|
+
|
|
171
|
+
Ƭ **FaasReactClientOptions**: `Object`
|
|
172
|
+
|
|
173
|
+
#### Type declaration
|
|
174
|
+
|
|
175
|
+
| Name | Type |
|
|
176
|
+
| :------ | :------ |
|
|
177
|
+
| `domain` | `string` |
|
|
178
|
+
| `onError?` | (`action`: `string`, `params`: `Record`\<`string`, `any`\>) => (`res`: [`ResponseError`](classes/ResponseError.md)) => `Promise`\<`void`\> |
|
|
179
|
+
| `options?` | [`Options`](#options) |
|
|
180
|
+
|
|
181
|
+
___
|
|
182
|
+
|
|
168
183
|
### Options
|
|
169
184
|
|
|
170
185
|
Ƭ **Options**: `RequestInit` & \{ `beforeRequest?`: (`{
|
|
@@ -264,10 +279,7 @@ Before use faas, you should initialize a FaasReactClient.
|
|
|
264
279
|
|
|
265
280
|
| Name | Type |
|
|
266
281
|
| :------ | :------ |
|
|
267
|
-
| `«destructured»` | `
|
|
268
|
-
| › `domain` | `string` |
|
|
269
|
-
| › `onError?` | (`action`: `string`, `params`: `Record`\<`string`, `any`\>) => (`res`: [`ResponseError`](classes/ResponseError.md)) => `Promise`\<`void`\> |
|
|
270
|
-
| › `options?` | [`Options`](#options) |
|
|
282
|
+
| `«destructured»` | [`FaasReactClientOptions`](#faasreactclientoptions) |
|
|
271
283
|
|
|
272
284
|
#### Returns
|
|
273
285
|
|
|
@@ -359,6 +371,16 @@ Create a [signal](https://preactjs.com/guide/v10/signals) with options
|
|
|
359
371
|
|
|
360
372
|
`Signal`\<`T`\>
|
|
361
373
|
|
|
374
|
+
**`Example`**
|
|
375
|
+
|
|
376
|
+
```ts
|
|
377
|
+
import { signal } from '@faasjs/react'
|
|
378
|
+
|
|
379
|
+
const count = signal(0, { debugName: 'count' })
|
|
380
|
+
|
|
381
|
+
count.value = 1
|
|
382
|
+
```
|
|
383
|
+
|
|
362
384
|
___
|
|
363
385
|
|
|
364
386
|
### useFaas
|
package/dist/index.d.mts
CHANGED
|
@@ -66,6 +66,11 @@ type useFaasOptions<PathOrData extends FaasAction> = {
|
|
|
66
66
|
debounce?: number
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
type FaasReactClientOptions = {
|
|
70
|
+
domain: string;
|
|
71
|
+
options?: Options;
|
|
72
|
+
onError?: (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
|
|
73
|
+
};
|
|
69
74
|
/**
|
|
70
75
|
* Before use faas, you should initialize a FaasReactClient.
|
|
71
76
|
*
|
|
@@ -79,11 +84,7 @@ type useFaasOptions<PathOrData extends FaasAction> = {
|
|
|
79
84
|
* })
|
|
80
85
|
* ```
|
|
81
86
|
*/
|
|
82
|
-
declare function FaasReactClient({ domain, options, onError, }:
|
|
83
|
-
domain: string;
|
|
84
|
-
options?: Options;
|
|
85
|
-
onError?: (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
|
|
86
|
-
}): FaasReactClientInstance;
|
|
87
|
+
declare function FaasReactClient({ domain, options, onError, }: FaasReactClientOptions): FaasReactClientInstance;
|
|
87
88
|
/**
|
|
88
89
|
* Get FaasReactClient instance
|
|
89
90
|
* @param domain {string} empty string for default domain
|
|
@@ -184,4 +185,4 @@ type SignalOptions = {
|
|
|
184
185
|
*/
|
|
185
186
|
declare function signal<T = any>(initialValue: any, options?: SignalOptions): _preact_signals_core.Signal<T>;
|
|
186
187
|
|
|
187
|
-
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasReactClient, FaasReactClientInstance, SignalOptions, faas, getClient, signal, useFaas, useFaasOptions };
|
|
188
|
+
export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useFaas, type useFaasOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,11 @@ type useFaasOptions<PathOrData extends FaasAction> = {
|
|
|
66
66
|
debounce?: number
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
type FaasReactClientOptions = {
|
|
70
|
+
domain: string;
|
|
71
|
+
options?: Options;
|
|
72
|
+
onError?: (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
|
|
73
|
+
};
|
|
69
74
|
/**
|
|
70
75
|
* Before use faas, you should initialize a FaasReactClient.
|
|
71
76
|
*
|
|
@@ -79,11 +84,7 @@ type useFaasOptions<PathOrData extends FaasAction> = {
|
|
|
79
84
|
* })
|
|
80
85
|
* ```
|
|
81
86
|
*/
|
|
82
|
-
declare function FaasReactClient({ domain, options, onError, }:
|
|
83
|
-
domain: string;
|
|
84
|
-
options?: Options;
|
|
85
|
-
onError?: (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
|
|
86
|
-
}): FaasReactClientInstance;
|
|
87
|
+
declare function FaasReactClient({ domain, options, onError, }: FaasReactClientOptions): FaasReactClientInstance;
|
|
87
88
|
/**
|
|
88
89
|
* Get FaasReactClient instance
|
|
89
90
|
* @param domain {string} empty string for default domain
|
|
@@ -184,4 +185,4 @@ type SignalOptions = {
|
|
|
184
185
|
*/
|
|
185
186
|
declare function signal<T = any>(initialValue: any, options?: SignalOptions): _preact_signals_core.Signal<T>;
|
|
186
187
|
|
|
187
|
-
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasReactClient, FaasReactClientInstance, SignalOptions, faas, getClient, signal, useFaas, useFaasOptions };
|
|
188
|
+
export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useFaas, type useFaasOptions };
|
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.17",
|
|
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.17"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "*",
|