@faasjs/react 0.0.3-beta.10 → 0.0.3-beta.100
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 +22 -83
- package/dist/index.d.mts +159 -0
- package/dist/index.d.ts +80 -42
- package/dist/index.js +106 -71
- package/dist/index.mjs +85 -34
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ React plugin for FaasJS.
|
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
|
-
npm install @faasjs/react
|
|
13
|
+
npm install @faasjs/react react react-dom
|
|
14
14
|
|
|
15
15
|
## Modules
|
|
16
16
|
|
|
@@ -20,14 +20,17 @@ React plugin for FaasJS.
|
|
|
20
20
|
- [Response](classes/Response.md)
|
|
21
21
|
- [ResponseError](classes/ResponseError.md)
|
|
22
22
|
|
|
23
|
+
### Interfaces
|
|
24
|
+
|
|
25
|
+
- [FaasDataInjection](interfaces/FaasDataInjection.md)
|
|
26
|
+
- [FaasDataWrapperProps](interfaces/FaasDataWrapperProps.md)
|
|
27
|
+
- [FaasReactClientInstance](interfaces/FaasReactClientInstance.md)
|
|
28
|
+
|
|
23
29
|
### Type Aliases
|
|
24
30
|
|
|
25
31
|
- [FaasAction](#faasaction)
|
|
26
32
|
- [FaasData](#faasdata)
|
|
27
|
-
- [FaasDataInjection](#faasdatainjection)
|
|
28
|
-
- [FaasDataWrapperProps](#faasdatawrapperprops)
|
|
29
33
|
- [FaasParams](#faasparams)
|
|
30
|
-
- [FaasReactClientInstance](#faasreactclientinstance)
|
|
31
34
|
- [Options](#options)
|
|
32
35
|
- [ResponseHeaders](#responseheaders)
|
|
33
36
|
|
|
@@ -59,60 +62,6 @@ ___
|
|
|
59
62
|
|
|
60
63
|
___
|
|
61
64
|
|
|
62
|
-
### FaasDataInjection
|
|
63
|
-
|
|
64
|
-
Ƭ **FaasDataInjection**<`Data`\>: `Object`
|
|
65
|
-
|
|
66
|
-
Injects FaasData props.
|
|
67
|
-
|
|
68
|
-
#### Type parameters
|
|
69
|
-
|
|
70
|
-
| Name | Type |
|
|
71
|
-
| :------ | :------ |
|
|
72
|
-
| `Data` | `any` |
|
|
73
|
-
|
|
74
|
-
#### Type declaration
|
|
75
|
-
|
|
76
|
-
| Name | Type |
|
|
77
|
-
| :------ | :------ |
|
|
78
|
-
| `action` | `string` \| `any` |
|
|
79
|
-
| `data` | `Data` |
|
|
80
|
-
| `error` | `any` |
|
|
81
|
-
| `loading` | `boolean` |
|
|
82
|
-
| `params` | `Record`<`string`, `any`\> |
|
|
83
|
-
| `promise` | `Promise`<[`Response`](classes/Response.md)<`Data`\>\> |
|
|
84
|
-
| `setData` | `React.Dispatch`<`React.SetStateAction`<`Data`\>\> |
|
|
85
|
-
| `setError` | `React.Dispatch`<`React.SetStateAction`<`any`\>\> |
|
|
86
|
-
| `setLoading` | `React.Dispatch`<`React.SetStateAction`<`boolean`\>\> |
|
|
87
|
-
| `setPromise` | `React.Dispatch`<`React.SetStateAction`<`Promise`<[`Response`](classes/Response.md)<`Data`\>\>\>\> |
|
|
88
|
-
| `reload` | (`params?`: `Record`<`string`, `any`\>) => `Promise`<[`Response`](classes/Response.md)<`Data`\>\> |
|
|
89
|
-
|
|
90
|
-
___
|
|
91
|
-
|
|
92
|
-
### FaasDataWrapperProps
|
|
93
|
-
|
|
94
|
-
Ƭ **FaasDataWrapperProps**<`PathOrData`\>: `Object`
|
|
95
|
-
|
|
96
|
-
#### Type parameters
|
|
97
|
-
|
|
98
|
-
| Name | Type |
|
|
99
|
-
| :------ | :------ |
|
|
100
|
-
| `PathOrData` | extends [`FaasAction`](#faasaction) |
|
|
101
|
-
|
|
102
|
-
#### Type declaration
|
|
103
|
-
|
|
104
|
-
| Name | Type | Description |
|
|
105
|
-
| :------ | :------ | :------ |
|
|
106
|
-
| `action` | `string` | - |
|
|
107
|
-
| `data?` | [`FaasData`](#faasdata)<`PathOrData`\> | use custom data, should work with setData |
|
|
108
|
-
| `fallback?` | `JSX.Element` \| ``false`` | - |
|
|
109
|
-
| `params?` | [`FaasParams`](#faasparams)<`PathOrData`\> | - |
|
|
110
|
-
| `setData?` | `React.Dispatch`<`React.SetStateAction`<[`FaasData`](#faasdata)<`PathOrData`\>\>\> | use custom setData, should work with data |
|
|
111
|
-
| `onDataChange?` | (`args`: [`FaasDataInjection`](#faasdatainjection)<[`FaasData`](#faasdata)<`PathOrData`\>\>) => `void` | - |
|
|
112
|
-
| `render?` | (`args`: [`FaasDataInjection`](#faasdatainjection)<[`FaasData`](#faasdata)<`PathOrData`\>\>) => `Element` \| `Element`[] | - |
|
|
113
|
-
|
|
114
|
-
___
|
|
115
|
-
|
|
116
65
|
### FaasParams
|
|
117
66
|
|
|
118
67
|
Ƭ **FaasParams**<`T`\>: `T` extends `FaasActionPaths` ? `FaasActions`[`T`][``"Params"``] : `any`
|
|
@@ -125,20 +74,6 @@ ___
|
|
|
125
74
|
|
|
126
75
|
___
|
|
127
76
|
|
|
128
|
-
### FaasReactClientInstance
|
|
129
|
-
|
|
130
|
-
Ƭ **FaasReactClientInstance**: `Object`
|
|
131
|
-
|
|
132
|
-
#### Type declaration
|
|
133
|
-
|
|
134
|
-
| Name | Type |
|
|
135
|
-
| :------ | :------ |
|
|
136
|
-
| `faas` | <PathOrData\>(`action`: `string` \| `PathOrData`, `params`: [`FaasParams`](#faasparams)<`PathOrData`\>) => `Promise`<[`Response`](classes/Response.md)<[`FaasData`](#faasdata)<`PathOrData`\>\>\> |
|
|
137
|
-
| `useFaas` | <PathOrData\>(`action`: `string` \| `PathOrData`, `defaultParams`: [`FaasParams`](#faasparams)<`PathOrData`\>) => [`FaasDataInjection`](#faasdatainjection)<[`FaasData`](#faasdata)<`PathOrData`\>\> |
|
|
138
|
-
| `FaasDataWrapper` | <PathOrData\>(`props`: [`FaasDataWrapperProps`](#faasdatawrapperprops)<`PathOrData`\>) => `Element` |
|
|
139
|
-
|
|
140
|
-
___
|
|
141
|
-
|
|
142
77
|
### Options
|
|
143
78
|
|
|
144
79
|
Ƭ **Options**: `RequestInit` & { `beforeRequest?`: (`{
|
|
@@ -173,7 +108,7 @@ A data wrapper for react components
|
|
|
173
108
|
|
|
174
109
|
| Name | Type |
|
|
175
110
|
| :------ | :------ |
|
|
176
|
-
| `props` | [`FaasDataWrapperProps`](
|
|
111
|
+
| `props` | [`FaasDataWrapperProps`](interfaces/FaasDataWrapperProps.md)<`PathOrData`\> |
|
|
177
112
|
|
|
178
113
|
#### Returns
|
|
179
114
|
|
|
@@ -194,7 +129,7 @@ ___
|
|
|
194
129
|
|
|
195
130
|
### FaasReactClient
|
|
196
131
|
|
|
197
|
-
▸ **FaasReactClient**(
|
|
132
|
+
▸ **FaasReactClient**(`«destructured»`): [`FaasReactClientInstance`](interfaces/FaasReactClientInstance.md)
|
|
198
133
|
|
|
199
134
|
Before use faas, you should initialize a FaasReactClient.
|
|
200
135
|
|
|
@@ -202,14 +137,14 @@ Before use faas, you should initialize a FaasReactClient.
|
|
|
202
137
|
|
|
203
138
|
| Name | Type |
|
|
204
139
|
| :------ | :------ |
|
|
205
|
-
|
|
|
206
|
-
| `
|
|
207
|
-
| `
|
|
208
|
-
| `
|
|
140
|
+
| `«destructured»` | `Object` |
|
|
141
|
+
| › `domain` | `string` |
|
|
142
|
+
| › `onError?` | (`action`: `string`, `params`: `Record`<`string`, `any`\>) => (`res`: [`ResponseError`](classes/ResponseError.md)) => `Promise`<`void`\> |
|
|
143
|
+
| › `options?` | [`Options`](#options) |
|
|
209
144
|
|
|
210
145
|
#### Returns
|
|
211
146
|
|
|
212
|
-
[`FaasReactClientInstance`](
|
|
147
|
+
[`FaasReactClientInstance`](interfaces/FaasReactClientInstance.md)
|
|
213
148
|
|
|
214
149
|
```ts
|
|
215
150
|
const client = FaasReactClient({
|
|
@@ -252,7 +187,7 @@ ___
|
|
|
252
187
|
|
|
253
188
|
### getClient
|
|
254
189
|
|
|
255
|
-
▸ **getClient**(`domain?`): [`FaasReactClientInstance`](
|
|
190
|
+
▸ **getClient**(`domain?`): [`FaasReactClientInstance`](interfaces/FaasReactClientInstance.md)
|
|
256
191
|
|
|
257
192
|
Get FaasReactClient instance
|
|
258
193
|
|
|
@@ -264,7 +199,7 @@ Get FaasReactClient instance
|
|
|
264
199
|
|
|
265
200
|
#### Returns
|
|
266
201
|
|
|
267
|
-
[`FaasReactClientInstance`](
|
|
202
|
+
[`FaasReactClientInstance`](interfaces/FaasReactClientInstance.md)
|
|
268
203
|
|
|
269
204
|
```ts
|
|
270
205
|
getClient()
|
|
@@ -276,7 +211,7 @@ ___
|
|
|
276
211
|
|
|
277
212
|
### useFaas
|
|
278
213
|
|
|
279
|
-
▸ **useFaas**<`PathOrData`\>(`action`, `defaultParams`): [`FaasDataInjection`](
|
|
214
|
+
▸ **useFaas**<`PathOrData`\>(`action`, `defaultParams`, `options?`): [`FaasDataInjection`](interfaces/FaasDataInjection.md)<[`FaasData`](#faasdata)<`PathOrData`\>\>
|
|
280
215
|
|
|
281
216
|
Request faas server with React hook
|
|
282
217
|
|
|
@@ -292,10 +227,14 @@ Request faas server with React hook
|
|
|
292
227
|
| :------ | :------ | :------ |
|
|
293
228
|
| `action` | `string` \| `PathOrData` | {string} action name |
|
|
294
229
|
| `defaultParams` | [`FaasParams`](#faasparams)<`PathOrData`\> | {object} initial action params |
|
|
230
|
+
| `options?` | `Object` | - |
|
|
231
|
+
| `options.data?` | [`FaasData`](#faasdata)<`PathOrData`\> | - |
|
|
232
|
+
| `options.setData?` | `Dispatch`<`SetStateAction`<[`FaasData`](#faasdata)<`PathOrData`\>\>\> | - |
|
|
233
|
+
| `options.skip?` | `boolean` | - |
|
|
295
234
|
|
|
296
235
|
#### Returns
|
|
297
236
|
|
|
298
|
-
[`FaasDataInjection`](
|
|
237
|
+
[`FaasDataInjection`](interfaces/FaasDataInjection.md)<[`FaasData`](#faasdata)<`PathOrData`\>\>
|
|
299
238
|
|
|
300
239
|
```ts
|
|
301
240
|
function Post ({ id }) {
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { FaasAction as FaasAction$1, FaasParams as FaasParams$1, FaasData as FaasData$1 } from '@faasjs/types';
|
|
2
|
+
export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
|
|
3
|
+
import { Options, ResponseError, Response as Response$1 } from '@faasjs/browser';
|
|
4
|
+
export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
|
|
5
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
+
import { ReactNode, ReactElement, Component } from 'react';
|
|
7
|
+
|
|
8
|
+
type FaasReactClientInstance = {
|
|
9
|
+
id: string
|
|
10
|
+
faas: <PathOrData extends FaasAction>(
|
|
11
|
+
action: string | PathOrData,
|
|
12
|
+
params: FaasParams<PathOrData>
|
|
13
|
+
) => Promise<Response<FaasData<PathOrData>>>
|
|
14
|
+
useFaas: <PathOrData extends FaasAction>(
|
|
15
|
+
action: string | PathOrData,
|
|
16
|
+
defaultParams: FaasParams<PathOrData>,
|
|
17
|
+
options?: useFaasOptions<PathOrData>,
|
|
18
|
+
) => FaasDataInjection<FaasData<PathOrData>>
|
|
19
|
+
FaasDataWrapper<PathOrData extends FaasAction>(props: FaasDataWrapperProps<PathOrData>): JSX.Element
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Injects FaasData props.
|
|
24
|
+
*/
|
|
25
|
+
type FaasDataInjection<Data = any> = {
|
|
26
|
+
action: string | any
|
|
27
|
+
params: Record<string, any>
|
|
28
|
+
loading: boolean
|
|
29
|
+
reloadTimes: number
|
|
30
|
+
data: Data
|
|
31
|
+
error: any
|
|
32
|
+
promise: Promise<Response<Data>>
|
|
33
|
+
reload(params?: Record<string, any>): Promise<Response<Data>>,
|
|
34
|
+
setData: React.Dispatch<React.SetStateAction<Data>>
|
|
35
|
+
setLoading: React.Dispatch<React.SetStateAction<boolean>>
|
|
36
|
+
setPromise: React.Dispatch<React.SetStateAction<Promise<Response<Data>>>>
|
|
37
|
+
setError: React.Dispatch<React.SetStateAction<any>>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type FaasDataWrapperProps<PathOrData extends FaasAction> = {
|
|
41
|
+
render?(args: FaasDataInjection<FaasData<PathOrData>>): JSX.Element | JSX.Element[]
|
|
42
|
+
children?: React.ReactElement<Partial<FaasDataInjection>>
|
|
43
|
+
fallback?: JSX.Element | false
|
|
44
|
+
action: string
|
|
45
|
+
params?: FaasParams<PathOrData>
|
|
46
|
+
onDataChange?(args: FaasDataInjection<FaasData<PathOrData>>): void
|
|
47
|
+
/** use custom data, should work with setData */
|
|
48
|
+
data?: FaasData<PathOrData>
|
|
49
|
+
/** use custom setData, should work with data */
|
|
50
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type useFaasOptions<PathOrData extends FaasAction> = {
|
|
54
|
+
params?: FaasParams<PathOrData>
|
|
55
|
+
data?: FaasData<PathOrData>
|
|
56
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
57
|
+
skip?: boolean
|
|
58
|
+
/** send the last request after milliseconds */
|
|
59
|
+
debounce?: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Before use faas, you should initialize a FaasReactClient.
|
|
64
|
+
*
|
|
65
|
+
* @param props.domain {string} The domain of your faas server
|
|
66
|
+
* @param props.options {Options} The options of client
|
|
67
|
+
* @returns {FaasReactClientInstance}
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* const client = FaasReactClient({
|
|
71
|
+
* domain: 'localhost:8080/api'
|
|
72
|
+
* })
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare function FaasReactClient({ domain, options, onError }: {
|
|
76
|
+
domain: string;
|
|
77
|
+
options?: Options;
|
|
78
|
+
onError?: (action: string, params: Record<string, any>) => (res: ResponseError) => Promise<void>;
|
|
79
|
+
}): FaasReactClientInstance;
|
|
80
|
+
/**
|
|
81
|
+
* Get FaasReactClient instance
|
|
82
|
+
* @param domain {string} empty string for default domain
|
|
83
|
+
* @returns {FaasReactClientInstance}
|
|
84
|
+
*
|
|
85
|
+
* ```ts
|
|
86
|
+
* getClient()
|
|
87
|
+
* // or
|
|
88
|
+
* getClient('another-domain')
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
declare function getClient(domain?: string): FaasReactClientInstance;
|
|
92
|
+
/**
|
|
93
|
+
* Request faas server
|
|
94
|
+
*
|
|
95
|
+
* @param action {string} action name
|
|
96
|
+
* @param params {object} action params
|
|
97
|
+
* @returns {Promise<Response<any>>}
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* faas<{ title: string }>('post/get', { id: 1 }).then(res => {
|
|
101
|
+
* console.log(res.data.title)
|
|
102
|
+
* })
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrData, params: FaasParams$1<PathOrData>): Promise<Response$1<FaasData$1<PathOrData>>>;
|
|
106
|
+
/**
|
|
107
|
+
* Request faas server with React hook
|
|
108
|
+
* @param action {string} action name
|
|
109
|
+
* @param defaultParams {object} initial action params
|
|
110
|
+
* @returns {FaasDataInjection<any>}
|
|
111
|
+
*
|
|
112
|
+
* ```ts
|
|
113
|
+
* function Post ({ id }) {
|
|
114
|
+
* const { data } = useFaas<{ title: string }>('post/get', { id })
|
|
115
|
+
* return <h1>{data.title}</h1>
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function useFaas<PathOrData extends FaasAction$1>(action: string | PathOrData, defaultParams: FaasParams$1<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<FaasData$1<PathOrData>>;
|
|
120
|
+
/**
|
|
121
|
+
* A data wrapper for react components
|
|
122
|
+
* @returns {JSX.Element}
|
|
123
|
+
*
|
|
124
|
+
* ```ts
|
|
125
|
+
* <FaasDataWrapper<{
|
|
126
|
+
* id: string
|
|
127
|
+
* title: string
|
|
128
|
+
* }>
|
|
129
|
+
* action='post/get'
|
|
130
|
+
* params={ { id: 1 } }
|
|
131
|
+
* render={ ({ data }) => <h1>{ data.title }</h1> }
|
|
132
|
+
* />
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
declare function FaasDataWrapper<PathOrData extends FaasAction$1>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
136
|
+
|
|
137
|
+
interface ErrorBoundaryProps {
|
|
138
|
+
children?: ReactNode;
|
|
139
|
+
onError?: (error: Error | null, info: any) => void;
|
|
140
|
+
errorChildren?: ReactElement<ErrorChildrenProps>;
|
|
141
|
+
}
|
|
142
|
+
type ErrorChildrenProps = {
|
|
143
|
+
error?: Error;
|
|
144
|
+
info?: any;
|
|
145
|
+
errorMessage?: string;
|
|
146
|
+
errorDescription?: string;
|
|
147
|
+
};
|
|
148
|
+
declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
149
|
+
error?: Error;
|
|
150
|
+
info?: {
|
|
151
|
+
componentStack?: string;
|
|
152
|
+
};
|
|
153
|
+
}> {
|
|
154
|
+
constructor(props: ErrorBoundaryProps);
|
|
155
|
+
componentDidCatch(error: Error | null, info: any): void;
|
|
156
|
+
render(): string | number | boolean | react_jsx_runtime.JSX.Element | Iterable<ReactNode>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasReactClient, FaasReactClientInstance, faas, getClient, useFaas, useFaasOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,44 +1,64 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { FaasBrowserClient, Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
|
|
3
|
-
import { FaasAction, FaasData, FaasParams } from '@faasjs/types';
|
|
1
|
+
import { FaasAction as FaasAction$1, FaasParams as FaasParams$1, FaasData as FaasData$1 } from '@faasjs/types';
|
|
4
2
|
export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
|
|
3
|
+
import { Options, ResponseError, Response as Response$1 } from '@faasjs/browser';
|
|
4
|
+
export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
|
|
5
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
|
+
import { ReactNode, ReactElement, Component } from 'react';
|
|
7
|
+
|
|
8
|
+
type FaasReactClientInstance = {
|
|
9
|
+
id: string
|
|
10
|
+
faas: <PathOrData extends FaasAction>(
|
|
11
|
+
action: string | PathOrData,
|
|
12
|
+
params: FaasParams<PathOrData>
|
|
13
|
+
) => Promise<Response<FaasData<PathOrData>>>
|
|
14
|
+
useFaas: <PathOrData extends FaasAction>(
|
|
15
|
+
action: string | PathOrData,
|
|
16
|
+
defaultParams: FaasParams<PathOrData>,
|
|
17
|
+
options?: useFaasOptions<PathOrData>,
|
|
18
|
+
) => FaasDataInjection<FaasData<PathOrData>>
|
|
19
|
+
FaasDataWrapper<PathOrData extends FaasAction>(props: FaasDataWrapperProps<PathOrData>): JSX.Element
|
|
20
|
+
}
|
|
5
21
|
|
|
6
22
|
/**
|
|
7
23
|
* Injects FaasData props.
|
|
8
24
|
*/
|
|
9
25
|
type FaasDataInjection<Data = any> = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
action: string | any
|
|
27
|
+
params: Record<string, any>
|
|
28
|
+
loading: boolean
|
|
29
|
+
reloadTimes: number
|
|
30
|
+
data: Data
|
|
31
|
+
error: any
|
|
32
|
+
promise: Promise<Response<Data>>
|
|
33
|
+
reload(params?: Record<string, any>): Promise<Response<Data>>,
|
|
34
|
+
setData: React.Dispatch<React.SetStateAction<Data>>
|
|
35
|
+
setLoading: React.Dispatch<React.SetStateAction<boolean>>
|
|
36
|
+
setPromise: React.Dispatch<React.SetStateAction<Promise<Response<Data>>>>
|
|
37
|
+
setError: React.Dispatch<React.SetStateAction<any>>
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
type FaasDataWrapperProps<PathOrData extends FaasAction> = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
render?(args: FaasDataInjection<FaasData<PathOrData>>): JSX.Element | JSX.Element[]
|
|
42
|
+
children?: React.ReactElement<Partial<FaasDataInjection>>
|
|
43
|
+
fallback?: JSX.Element | false
|
|
44
|
+
action: string
|
|
45
|
+
params?: FaasParams<PathOrData>
|
|
46
|
+
onDataChange?(args: FaasDataInjection<FaasData<PathOrData>>): void
|
|
47
|
+
/** use custom data, should work with setData */
|
|
48
|
+
data?: FaasData<PathOrData>
|
|
49
|
+
/** use custom setData, should work with data */
|
|
50
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type useFaasOptions<PathOrData extends FaasAction> = {
|
|
54
|
+
params?: FaasParams<PathOrData>
|
|
55
|
+
data?: FaasData<PathOrData>
|
|
56
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
57
|
+
skip?: boolean
|
|
58
|
+
/** send the last request after milliseconds */
|
|
59
|
+
debounce?: number
|
|
60
|
+
}
|
|
61
|
+
|
|
42
62
|
/**
|
|
43
63
|
* Before use faas, you should initialize a FaasReactClient.
|
|
44
64
|
*
|
|
@@ -82,7 +102,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
|
|
|
82
102
|
* })
|
|
83
103
|
* ```
|
|
84
104
|
*/
|
|
85
|
-
declare function faas<PathOrData extends FaasAction>(action: string | PathOrData, params: FaasParams<PathOrData>): Promise<Response<FaasData<PathOrData>>>;
|
|
105
|
+
declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrData, params: FaasParams$1<PathOrData>): Promise<Response$1<FaasData$1<PathOrData>>>;
|
|
86
106
|
/**
|
|
87
107
|
* Request faas server with React hook
|
|
88
108
|
* @param action {string} action name
|
|
@@ -96,11 +116,7 @@ declare function faas<PathOrData extends FaasAction>(action: string | PathOrData
|
|
|
96
116
|
* }
|
|
97
117
|
* ```
|
|
98
118
|
*/
|
|
99
|
-
declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrData, defaultParams: FaasParams<PathOrData>, options?:
|
|
100
|
-
data?: FaasData<PathOrData>;
|
|
101
|
-
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
|
|
102
|
-
skip?: boolean;
|
|
103
|
-
}): FaasDataInjection<FaasData<PathOrData>>;
|
|
119
|
+
declare function useFaas<PathOrData extends FaasAction$1>(action: string | PathOrData, defaultParams: FaasParams$1<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<FaasData$1<PathOrData>>;
|
|
104
120
|
/**
|
|
105
121
|
* A data wrapper for react components
|
|
106
122
|
* @returns {JSX.Element}
|
|
@@ -116,6 +132,28 @@ declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrD
|
|
|
116
132
|
* />
|
|
117
133
|
* ```
|
|
118
134
|
*/
|
|
119
|
-
declare function FaasDataWrapper<PathOrData extends FaasAction>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
135
|
+
declare function FaasDataWrapper<PathOrData extends FaasAction$1>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
136
|
+
|
|
137
|
+
interface ErrorBoundaryProps {
|
|
138
|
+
children?: ReactNode;
|
|
139
|
+
onError?: (error: Error | null, info: any) => void;
|
|
140
|
+
errorChildren?: ReactElement<ErrorChildrenProps>;
|
|
141
|
+
}
|
|
142
|
+
type ErrorChildrenProps = {
|
|
143
|
+
error?: Error;
|
|
144
|
+
info?: any;
|
|
145
|
+
errorMessage?: string;
|
|
146
|
+
errorDescription?: string;
|
|
147
|
+
};
|
|
148
|
+
declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
149
|
+
error?: Error;
|
|
150
|
+
info?: {
|
|
151
|
+
componentStack?: string;
|
|
152
|
+
};
|
|
153
|
+
}> {
|
|
154
|
+
constructor(props: ErrorBoundaryProps);
|
|
155
|
+
componentDidCatch(error: Error | null, info: any): void;
|
|
156
|
+
render(): string | number | boolean | react_jsx_runtime.JSX.Element | Iterable<ReactNode>;
|
|
157
|
+
}
|
|
120
158
|
|
|
121
|
-
export { FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasReactClient, FaasReactClientInstance, faas, getClient, useFaas };
|
|
159
|
+
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasReactClient, FaasReactClientInstance, faas, getClient, useFaas, useFaasOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,41 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var react = require('react');
|
|
4
|
+
var browser = require('@faasjs/browser');
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
19
6
|
|
|
20
|
-
// src/
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
FaasDataWrapper: () => FaasDataWrapper,
|
|
24
|
-
FaasReactClient: () => FaasReactClient,
|
|
25
|
-
faas: () => faas,
|
|
26
|
-
getClient: () => getClient,
|
|
27
|
-
useFaas: () => useFaas
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(src_exports);
|
|
30
|
-
var import_browser = require("@faasjs/browser");
|
|
31
|
-
var import_react = require("react");
|
|
7
|
+
// src/client.tsx
|
|
32
8
|
var clients = {};
|
|
33
9
|
function FaasReactClient({
|
|
34
10
|
domain,
|
|
35
11
|
options,
|
|
36
12
|
onError
|
|
37
13
|
}) {
|
|
38
|
-
const client = new
|
|
14
|
+
const client = new browser.FaasBrowserClient(domain, options);
|
|
39
15
|
async function faas2(action, params) {
|
|
40
16
|
if (onError)
|
|
41
17
|
return client.action(action, params).catch(async (res) => {
|
|
@@ -47,46 +23,63 @@ function FaasReactClient({
|
|
|
47
23
|
function useFaas2(action, defaultParams, options2) {
|
|
48
24
|
if (!options2)
|
|
49
25
|
options2 = {};
|
|
50
|
-
const [loading, setLoading] =
|
|
51
|
-
const [data, setData] =
|
|
52
|
-
const [error, setError] =
|
|
53
|
-
const [promise, setPromise] =
|
|
54
|
-
const [params, setParams] =
|
|
55
|
-
const [reloadTimes, setReloadTimes] =
|
|
56
|
-
|
|
26
|
+
const [loading, setLoading] = react.useState(true);
|
|
27
|
+
const [data, setData] = react.useState();
|
|
28
|
+
const [error, setError] = react.useState();
|
|
29
|
+
const [promise, setPromise] = react.useState();
|
|
30
|
+
const [params, setParams] = react.useState(defaultParams);
|
|
31
|
+
const [reloadTimes, setReloadTimes] = react.useState(0);
|
|
32
|
+
const [fails, setFails] = react.useState(0);
|
|
33
|
+
react.useEffect(function() {
|
|
57
34
|
if (JSON.stringify(defaultParams) !== JSON.stringify(params)) {
|
|
58
35
|
setParams(defaultParams);
|
|
59
36
|
}
|
|
60
37
|
}, [JSON.stringify(defaultParams)]);
|
|
61
|
-
|
|
62
|
-
if (options2 == null ? void 0 : options2.skip) {
|
|
38
|
+
react.useEffect(function() {
|
|
39
|
+
if (!action || (options2 == null ? void 0 : options2.skip)) {
|
|
63
40
|
setLoading(false);
|
|
64
41
|
return;
|
|
65
42
|
}
|
|
66
43
|
setLoading(true);
|
|
67
44
|
const controller = new AbortController();
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
45
|
+
function send() {
|
|
46
|
+
const request = client.action(action, options2.params || params, { signal: controller.signal });
|
|
47
|
+
setPromise(request);
|
|
48
|
+
request.then((r) => (options2 == null ? void 0 : options2.setData) ? options2.setData(r.data) : setData(r.data)).catch(async (e) => {
|
|
49
|
+
if ((e == null ? void 0 : e.message) === "The user aborted a request." || (e == null ? void 0 : e.message) === "Aborted")
|
|
50
|
+
return;
|
|
51
|
+
if (!fails && typeof (e == null ? void 0 : e.message) === "string" && e.message.indexOf("Failed to fetch") >= 0) {
|
|
52
|
+
console.warn(`FaasReactClient: ${e.message} retry...`);
|
|
53
|
+
setFails(1);
|
|
54
|
+
return send();
|
|
78
55
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
56
|
+
if (onError)
|
|
57
|
+
try {
|
|
58
|
+
await onError(action, params)(e);
|
|
59
|
+
} catch (error2) {
|
|
60
|
+
setError(error2);
|
|
61
|
+
}
|
|
62
|
+
else
|
|
63
|
+
setError(e);
|
|
64
|
+
return Promise.reject(e);
|
|
65
|
+
}).finally(() => setLoading(false));
|
|
66
|
+
}
|
|
67
|
+
if (options2 == null ? void 0 : options2.debounce) {
|
|
68
|
+
const timeout = setTimeout(send, options2.debounce);
|
|
69
|
+
return () => {
|
|
70
|
+
clearTimeout(timeout);
|
|
71
|
+
controller.abort();
|
|
72
|
+
setLoading(false);
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
send();
|
|
83
76
|
return () => {
|
|
84
77
|
controller.abort();
|
|
85
78
|
setLoading(false);
|
|
86
79
|
};
|
|
87
80
|
}, [
|
|
88
81
|
action,
|
|
89
|
-
JSON.stringify(params),
|
|
82
|
+
JSON.stringify(options2.params || params),
|
|
90
83
|
reloadTimes,
|
|
91
84
|
options2.skip
|
|
92
85
|
]);
|
|
@@ -95,6 +88,7 @@ function FaasReactClient({
|
|
|
95
88
|
params,
|
|
96
89
|
loading,
|
|
97
90
|
data: (options2 == null ? void 0 : options2.data) || data,
|
|
91
|
+
reloadTimes,
|
|
98
92
|
error,
|
|
99
93
|
promise,
|
|
100
94
|
async reload(params2) {
|
|
@@ -110,6 +104,7 @@ function FaasReactClient({
|
|
|
110
104
|
};
|
|
111
105
|
}
|
|
112
106
|
const reactClient = {
|
|
107
|
+
id: client.id,
|
|
113
108
|
faas: faas2,
|
|
114
109
|
useFaas: useFaas2,
|
|
115
110
|
FaasDataWrapper({
|
|
@@ -117,6 +112,7 @@ function FaasReactClient({
|
|
|
117
112
|
params,
|
|
118
113
|
fallback,
|
|
119
114
|
render,
|
|
115
|
+
children,
|
|
120
116
|
onDataChange,
|
|
121
117
|
data,
|
|
122
118
|
setData
|
|
@@ -125,17 +121,21 @@ function FaasReactClient({
|
|
|
125
121
|
data,
|
|
126
122
|
setData
|
|
127
123
|
});
|
|
128
|
-
const [loaded, setLoaded] =
|
|
129
|
-
|
|
124
|
+
const [loaded, setLoaded] = react.useState(false);
|
|
125
|
+
react.useEffect(function() {
|
|
130
126
|
if (!loaded && !request.loading)
|
|
131
127
|
setLoaded(true);
|
|
132
128
|
}, [request.loading]);
|
|
133
|
-
|
|
129
|
+
react.useEffect(function() {
|
|
134
130
|
if (onDataChange)
|
|
135
131
|
onDataChange(request);
|
|
136
132
|
}, [JSON.stringify(request.data)]);
|
|
137
|
-
if (loaded)
|
|
138
|
-
|
|
133
|
+
if (loaded) {
|
|
134
|
+
if (children)
|
|
135
|
+
return react.cloneElement(children, request);
|
|
136
|
+
if (render)
|
|
137
|
+
return render(request);
|
|
138
|
+
}
|
|
139
139
|
return fallback || null;
|
|
140
140
|
}
|
|
141
141
|
};
|
|
@@ -155,21 +155,56 @@ function useFaas(action, defaultParams, options) {
|
|
|
155
155
|
return getClient().useFaas(action, defaultParams, options);
|
|
156
156
|
}
|
|
157
157
|
function FaasDataWrapper(props) {
|
|
158
|
-
const [client, setClient] =
|
|
159
|
-
|
|
158
|
+
const [client, setClient] = react.useState();
|
|
159
|
+
react.useEffect(() => {
|
|
160
160
|
if (client)
|
|
161
161
|
return;
|
|
162
162
|
setClient(getClient());
|
|
163
163
|
}, []);
|
|
164
164
|
if (!client)
|
|
165
165
|
return props.fallback || null;
|
|
166
|
-
return
|
|
166
|
+
return /* @__PURE__ */ jsxRuntime.jsx(client.FaasDataWrapper, { ...props });
|
|
167
167
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
168
|
+
var ErrorBoundary = class extends react.Component {
|
|
169
|
+
constructor(props) {
|
|
170
|
+
super(props);
|
|
171
|
+
this.state = {
|
|
172
|
+
error: void 0,
|
|
173
|
+
info: { componentStack: "" }
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
componentDidCatch(error, info) {
|
|
177
|
+
this.setState({
|
|
178
|
+
error,
|
|
179
|
+
info
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
render() {
|
|
183
|
+
var _a;
|
|
184
|
+
const errorMessage = (this.state.error || "").toString();
|
|
185
|
+
const errorDescription = ((_a = this.state.info) == null ? void 0 : _a.componentStack) ? this.state.info.componentStack : null;
|
|
186
|
+
if (this.state.error) {
|
|
187
|
+
if (this.props.onError)
|
|
188
|
+
this.props.onError(this.state.error, this.state.info);
|
|
189
|
+
if (this.props.errorChildren)
|
|
190
|
+
return react.cloneElement(this.props.errorChildren, {
|
|
191
|
+
error: this.state.error,
|
|
192
|
+
info: this.state.info,
|
|
193
|
+
errorMessage,
|
|
194
|
+
errorDescription
|
|
195
|
+
});
|
|
196
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
197
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { children: errorMessage }),
|
|
198
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { children: errorDescription })
|
|
199
|
+
] });
|
|
200
|
+
}
|
|
201
|
+
return this.props.children;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
exports.ErrorBoundary = ErrorBoundary;
|
|
206
|
+
exports.FaasDataWrapper = FaasDataWrapper;
|
|
207
|
+
exports.FaasReactClient = FaasReactClient;
|
|
208
|
+
exports.faas = faas;
|
|
209
|
+
exports.getClient = getClient;
|
|
210
|
+
exports.useFaas = useFaas;
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
useState,
|
|
7
|
-
useEffect,
|
|
8
|
-
createElement
|
|
9
|
-
} from "react";
|
|
1
|
+
import { useState, useEffect, cloneElement, Component } from 'react';
|
|
2
|
+
import { FaasBrowserClient } from '@faasjs/browser';
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
// src/client.tsx
|
|
10
6
|
var clients = {};
|
|
11
7
|
function FaasReactClient({
|
|
12
8
|
domain,
|
|
@@ -31,40 +27,57 @@ function FaasReactClient({
|
|
|
31
27
|
const [promise, setPromise] = useState();
|
|
32
28
|
const [params, setParams] = useState(defaultParams);
|
|
33
29
|
const [reloadTimes, setReloadTimes] = useState(0);
|
|
30
|
+
const [fails, setFails] = useState(0);
|
|
34
31
|
useEffect(function() {
|
|
35
32
|
if (JSON.stringify(defaultParams) !== JSON.stringify(params)) {
|
|
36
33
|
setParams(defaultParams);
|
|
37
34
|
}
|
|
38
35
|
}, [JSON.stringify(defaultParams)]);
|
|
39
36
|
useEffect(function() {
|
|
40
|
-
if (options2 == null ? void 0 : options2.skip) {
|
|
37
|
+
if (!action || (options2 == null ? void 0 : options2.skip)) {
|
|
41
38
|
setLoading(false);
|
|
42
39
|
return;
|
|
43
40
|
}
|
|
44
41
|
setLoading(true);
|
|
45
42
|
const controller = new AbortController();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
43
|
+
function send() {
|
|
44
|
+
const request = client.action(action, options2.params || params, { signal: controller.signal });
|
|
45
|
+
setPromise(request);
|
|
46
|
+
request.then((r) => (options2 == null ? void 0 : options2.setData) ? options2.setData(r.data) : setData(r.data)).catch(async (e) => {
|
|
47
|
+
if ((e == null ? void 0 : e.message) === "The user aborted a request." || (e == null ? void 0 : e.message) === "Aborted")
|
|
48
|
+
return;
|
|
49
|
+
if (!fails && typeof (e == null ? void 0 : e.message) === "string" && e.message.indexOf("Failed to fetch") >= 0) {
|
|
50
|
+
console.warn(`FaasReactClient: ${e.message} retry...`);
|
|
51
|
+
setFails(1);
|
|
52
|
+
return send();
|
|
56
53
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
if (onError)
|
|
55
|
+
try {
|
|
56
|
+
await onError(action, params)(e);
|
|
57
|
+
} catch (error2) {
|
|
58
|
+
setError(error2);
|
|
59
|
+
}
|
|
60
|
+
else
|
|
61
|
+
setError(e);
|
|
62
|
+
return Promise.reject(e);
|
|
63
|
+
}).finally(() => setLoading(false));
|
|
64
|
+
}
|
|
65
|
+
if (options2 == null ? void 0 : options2.debounce) {
|
|
66
|
+
const timeout = setTimeout(send, options2.debounce);
|
|
67
|
+
return () => {
|
|
68
|
+
clearTimeout(timeout);
|
|
69
|
+
controller.abort();
|
|
70
|
+
setLoading(false);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
send();
|
|
61
74
|
return () => {
|
|
62
75
|
controller.abort();
|
|
63
76
|
setLoading(false);
|
|
64
77
|
};
|
|
65
78
|
}, [
|
|
66
79
|
action,
|
|
67
|
-
JSON.stringify(params),
|
|
80
|
+
JSON.stringify(options2.params || params),
|
|
68
81
|
reloadTimes,
|
|
69
82
|
options2.skip
|
|
70
83
|
]);
|
|
@@ -73,6 +86,7 @@ function FaasReactClient({
|
|
|
73
86
|
params,
|
|
74
87
|
loading,
|
|
75
88
|
data: (options2 == null ? void 0 : options2.data) || data,
|
|
89
|
+
reloadTimes,
|
|
76
90
|
error,
|
|
77
91
|
promise,
|
|
78
92
|
async reload(params2) {
|
|
@@ -88,6 +102,7 @@ function FaasReactClient({
|
|
|
88
102
|
};
|
|
89
103
|
}
|
|
90
104
|
const reactClient = {
|
|
105
|
+
id: client.id,
|
|
91
106
|
faas: faas2,
|
|
92
107
|
useFaas: useFaas2,
|
|
93
108
|
FaasDataWrapper({
|
|
@@ -95,6 +110,7 @@ function FaasReactClient({
|
|
|
95
110
|
params,
|
|
96
111
|
fallback,
|
|
97
112
|
render,
|
|
113
|
+
children,
|
|
98
114
|
onDataChange,
|
|
99
115
|
data,
|
|
100
116
|
setData
|
|
@@ -112,8 +128,12 @@ function FaasReactClient({
|
|
|
112
128
|
if (onDataChange)
|
|
113
129
|
onDataChange(request);
|
|
114
130
|
}, [JSON.stringify(request.data)]);
|
|
115
|
-
if (loaded)
|
|
116
|
-
|
|
131
|
+
if (loaded) {
|
|
132
|
+
if (children)
|
|
133
|
+
return cloneElement(children, request);
|
|
134
|
+
if (render)
|
|
135
|
+
return render(request);
|
|
136
|
+
}
|
|
117
137
|
return fallback || null;
|
|
118
138
|
}
|
|
119
139
|
};
|
|
@@ -141,12 +161,43 @@ function FaasDataWrapper(props) {
|
|
|
141
161
|
}, []);
|
|
142
162
|
if (!client)
|
|
143
163
|
return props.fallback || null;
|
|
144
|
-
return
|
|
164
|
+
return /* @__PURE__ */ jsx(client.FaasDataWrapper, { ...props });
|
|
145
165
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
166
|
+
var ErrorBoundary = class extends Component {
|
|
167
|
+
constructor(props) {
|
|
168
|
+
super(props);
|
|
169
|
+
this.state = {
|
|
170
|
+
error: void 0,
|
|
171
|
+
info: { componentStack: "" }
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
componentDidCatch(error, info) {
|
|
175
|
+
this.setState({
|
|
176
|
+
error,
|
|
177
|
+
info
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
render() {
|
|
181
|
+
var _a;
|
|
182
|
+
const errorMessage = (this.state.error || "").toString();
|
|
183
|
+
const errorDescription = ((_a = this.state.info) == null ? void 0 : _a.componentStack) ? this.state.info.componentStack : null;
|
|
184
|
+
if (this.state.error) {
|
|
185
|
+
if (this.props.onError)
|
|
186
|
+
this.props.onError(this.state.error, this.state.info);
|
|
187
|
+
if (this.props.errorChildren)
|
|
188
|
+
return cloneElement(this.props.errorChildren, {
|
|
189
|
+
error: this.state.error,
|
|
190
|
+
info: this.state.info,
|
|
191
|
+
errorMessage,
|
|
192
|
+
errorDescription
|
|
193
|
+
});
|
|
194
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
195
|
+
/* @__PURE__ */ jsx("p", { children: errorMessage }),
|
|
196
|
+
/* @__PURE__ */ jsx("pre", { children: errorDescription })
|
|
197
|
+
] });
|
|
198
|
+
}
|
|
199
|
+
return this.props.children;
|
|
200
|
+
}
|
|
152
201
|
};
|
|
202
|
+
|
|
203
|
+
export { ErrorBoundary, FaasDataWrapper, FaasReactClient, faas, getClient, useFaas };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/react",
|
|
3
|
-
"version": "0.0.3-beta.
|
|
3
|
+
"version": "0.0.3-beta.100",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -16,15 +16,15 @@
|
|
|
16
16
|
},
|
|
17
17
|
"funding": "https://github.com/sponsors/faasjs",
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "tsup src/index.tsx --
|
|
20
|
-
"build:types": "tsup-node src/index.tsx --dts-only"
|
|
19
|
+
"build": "tsup src/index.tsx --config ../../tsup.config.json"
|
|
21
20
|
},
|
|
22
21
|
"files": [
|
|
23
22
|
"dist"
|
|
24
23
|
],
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"@faasjs/browser": "
|
|
27
|
-
|
|
25
|
+
"@faasjs/browser": "0.0.3-beta.100"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
28
|
"react": "*"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|