@faasjs/react 2.7.0 → 2.8.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 +4 -3
- package/dist/index.d.mts +20 -25
- package/dist/index.d.ts +20 -25
- package/dist/index.js +44 -49
- package/dist/index.mjs +45 -51
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -61,12 +61,13 @@ const client = FaasReactClient({
|
|
|
61
61
|
|
|
62
62
|
## Functions
|
|
63
63
|
|
|
64
|
-
- [FaasDataWrapper](functions/FaasDataWrapper.md)
|
|
65
|
-
- [FaasReactClient](functions/FaasReactClient.md)
|
|
66
|
-
- [OptionalWrapper](functions/OptionalWrapper.md)
|
|
67
64
|
- [createSplitedContext](functions/createSplitedContext.md)
|
|
68
65
|
- [createSplittingContext](functions/createSplittingContext.md)
|
|
69
66
|
- [faas](functions/faas.md)
|
|
67
|
+
- [FaasDataWrapper](functions/FaasDataWrapper.md)
|
|
68
|
+
- [FaasReactClient](functions/FaasReactClient.md)
|
|
70
69
|
- [getClient](functions/getClient.md)
|
|
70
|
+
- [OptionalWrapper](functions/OptionalWrapper.md)
|
|
71
71
|
- [useConstant](functions/useConstant.md)
|
|
72
72
|
- [useFaas](functions/useFaas.md)
|
|
73
|
+
- [withFaasData](functions/withFaasData.md)
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FaasAction
|
|
1
|
+
import { FaasAction, FaasParams, FaasData } from '@faasjs/types';
|
|
2
2
|
export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
|
|
3
3
|
import { Options, ResponseError, Response as Response$1 } from '@faasjs/browser';
|
|
4
4
|
export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
|
|
@@ -119,6 +119,7 @@ type FaasDataWrapperProps<PathOrData extends FaasAction> = {
|
|
|
119
119
|
data?: FaasData<PathOrData>
|
|
120
120
|
/** use custom setData, should work with data */
|
|
121
121
|
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
122
|
+
domain?: string
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
type useFaasOptions<PathOrData extends FaasAction> = {
|
|
@@ -153,6 +154,7 @@ type FaasReactClientOptions = {
|
|
|
153
154
|
declare function FaasReactClient({ domain, options, onError, }: FaasReactClientOptions): FaasReactClientInstance;
|
|
154
155
|
/**
|
|
155
156
|
* Get FaasReactClient instance
|
|
157
|
+
*
|
|
156
158
|
* @param domain {string} empty string for default domain
|
|
157
159
|
* @returns {FaasReactClientInstance}
|
|
158
160
|
*
|
|
@@ -178,7 +180,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
|
|
|
178
180
|
* })
|
|
179
181
|
* ```
|
|
180
182
|
*/
|
|
181
|
-
declare function faas<PathOrData extends FaasAction
|
|
183
|
+
declare function faas<PathOrData extends FaasAction>(action: string | PathOrData, params: FaasParams<PathOrData>): Promise<Response$1<FaasData<PathOrData>>>;
|
|
182
184
|
/**
|
|
183
185
|
* Request faas server with React hook
|
|
184
186
|
*
|
|
@@ -194,28 +196,7 @@ declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrDa
|
|
|
194
196
|
* }
|
|
195
197
|
* ```
|
|
196
198
|
*/
|
|
197
|
-
declare function useFaas<PathOrData extends FaasAction
|
|
198
|
-
/**
|
|
199
|
-
* A data wrapper for react components
|
|
200
|
-
*
|
|
201
|
-
* @returns {JSX.Element}
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```tsx
|
|
205
|
-
* <FaasDataWrapper<{
|
|
206
|
-
* id: string
|
|
207
|
-
* title: string
|
|
208
|
-
* }>
|
|
209
|
-
* action='post/get'
|
|
210
|
-
* params={ { id: 1 } }
|
|
211
|
-
* render={ ({ data }) => <h1>{ data.title }</h1> }
|
|
212
|
-
* />
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
declare function FaasDataWrapper<PathOrData extends FaasAction$1>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
216
|
-
declare namespace FaasDataWrapper {
|
|
217
|
-
var whyDidYouRender: boolean;
|
|
218
|
-
}
|
|
199
|
+
declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrData, defaultParams: FaasParams<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<FaasData<PathOrData>>;
|
|
219
200
|
|
|
220
201
|
interface ErrorBoundaryProps {
|
|
221
202
|
children?: ReactNode;
|
|
@@ -240,6 +221,20 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
|
240
221
|
render(): string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
|
|
241
222
|
}
|
|
242
223
|
|
|
224
|
+
declare function FaasDataWrapper<PathOrData extends FaasAction>({ action, params, fallback, render, children, onDataChange, data, setData, domain, }: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
225
|
+
declare namespace FaasDataWrapper {
|
|
226
|
+
var whyDidYouRender: boolean;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* HOC to wrap a component with FaasDataWrapper
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```tsx
|
|
233
|
+
* const MyComponent = withFaasData(({ data }) => <div>{data.name}</div>, { action: 'test', params: { a: 1 } })
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function withFaasData<PathOrData extends FaasAction, TComponentProps extends FaasDataInjection<PathOrData> = FaasDataInjection<PathOrData>>(Component: React.FC<TComponentProps & Record<string, any>>, faasProps: FaasDataWrapperProps<PathOrData>): React.FC<Omit<TComponentProps, keyof FaasDataInjection> & Record<string, any>>;
|
|
237
|
+
|
|
243
238
|
type OptionalWrapperProps<TWrapper extends ComponentType<{
|
|
244
239
|
children: ReactNode;
|
|
245
240
|
}> = any> = {
|
|
@@ -270,4 +265,4 @@ declare const OptionalWrapper: React.FC<OptionalWrapperProps> & {
|
|
|
270
265
|
whyDidYouRender: boolean;
|
|
271
266
|
};
|
|
272
267
|
|
|
273
|
-
export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, OptionalWrapper, type OptionalWrapperProps, createSplitedContext, createSplittingContext, faas, getClient, useConstant, useFaas, type useFaasOptions };
|
|
268
|
+
export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, OptionalWrapper, type OptionalWrapperProps, createSplitedContext, createSplittingContext, faas, getClient, useConstant, useFaas, type useFaasOptions, withFaasData };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FaasAction
|
|
1
|
+
import { FaasAction, FaasParams, FaasData } from '@faasjs/types';
|
|
2
2
|
export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
|
|
3
3
|
import { Options, ResponseError, Response as Response$1 } from '@faasjs/browser';
|
|
4
4
|
export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
|
|
@@ -119,6 +119,7 @@ type FaasDataWrapperProps<PathOrData extends FaasAction> = {
|
|
|
119
119
|
data?: FaasData<PathOrData>
|
|
120
120
|
/** use custom setData, should work with data */
|
|
121
121
|
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
122
|
+
domain?: string
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
type useFaasOptions<PathOrData extends FaasAction> = {
|
|
@@ -153,6 +154,7 @@ type FaasReactClientOptions = {
|
|
|
153
154
|
declare function FaasReactClient({ domain, options, onError, }: FaasReactClientOptions): FaasReactClientInstance;
|
|
154
155
|
/**
|
|
155
156
|
* Get FaasReactClient instance
|
|
157
|
+
*
|
|
156
158
|
* @param domain {string} empty string for default domain
|
|
157
159
|
* @returns {FaasReactClientInstance}
|
|
158
160
|
*
|
|
@@ -178,7 +180,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
|
|
|
178
180
|
* })
|
|
179
181
|
* ```
|
|
180
182
|
*/
|
|
181
|
-
declare function faas<PathOrData extends FaasAction
|
|
183
|
+
declare function faas<PathOrData extends FaasAction>(action: string | PathOrData, params: FaasParams<PathOrData>): Promise<Response$1<FaasData<PathOrData>>>;
|
|
182
184
|
/**
|
|
183
185
|
* Request faas server with React hook
|
|
184
186
|
*
|
|
@@ -194,28 +196,7 @@ declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrDa
|
|
|
194
196
|
* }
|
|
195
197
|
* ```
|
|
196
198
|
*/
|
|
197
|
-
declare function useFaas<PathOrData extends FaasAction
|
|
198
|
-
/**
|
|
199
|
-
* A data wrapper for react components
|
|
200
|
-
*
|
|
201
|
-
* @returns {JSX.Element}
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```tsx
|
|
205
|
-
* <FaasDataWrapper<{
|
|
206
|
-
* id: string
|
|
207
|
-
* title: string
|
|
208
|
-
* }>
|
|
209
|
-
* action='post/get'
|
|
210
|
-
* params={ { id: 1 } }
|
|
211
|
-
* render={ ({ data }) => <h1>{ data.title }</h1> }
|
|
212
|
-
* />
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
declare function FaasDataWrapper<PathOrData extends FaasAction$1>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
216
|
-
declare namespace FaasDataWrapper {
|
|
217
|
-
var whyDidYouRender: boolean;
|
|
218
|
-
}
|
|
199
|
+
declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrData, defaultParams: FaasParams<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<FaasData<PathOrData>>;
|
|
219
200
|
|
|
220
201
|
interface ErrorBoundaryProps {
|
|
221
202
|
children?: ReactNode;
|
|
@@ -240,6 +221,20 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
|
240
221
|
render(): string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
|
|
241
222
|
}
|
|
242
223
|
|
|
224
|
+
declare function FaasDataWrapper<PathOrData extends FaasAction>({ action, params, fallback, render, children, onDataChange, data, setData, domain, }: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
225
|
+
declare namespace FaasDataWrapper {
|
|
226
|
+
var whyDidYouRender: boolean;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* HOC to wrap a component with FaasDataWrapper
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```tsx
|
|
233
|
+
* const MyComponent = withFaasData(({ data }) => <div>{data.name}</div>, { action: 'test', params: { a: 1 } })
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
declare function withFaasData<PathOrData extends FaasAction, TComponentProps extends FaasDataInjection<PathOrData> = FaasDataInjection<PathOrData>>(Component: React.FC<TComponentProps & Record<string, any>>, faasProps: FaasDataWrapperProps<PathOrData>): React.FC<Omit<TComponentProps, keyof FaasDataInjection> & Record<string, any>>;
|
|
237
|
+
|
|
243
238
|
type OptionalWrapperProps<TWrapper extends ComponentType<{
|
|
244
239
|
children: ReactNode;
|
|
245
240
|
}> = any> = {
|
|
@@ -270,4 +265,4 @@ declare const OptionalWrapper: React.FC<OptionalWrapperProps> & {
|
|
|
270
265
|
whyDidYouRender: boolean;
|
|
271
266
|
};
|
|
272
267
|
|
|
273
|
-
export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, OptionalWrapper, type OptionalWrapperProps, createSplitedContext, createSplittingContext, faas, getClient, useConstant, useFaas, type useFaasOptions };
|
|
268
|
+
export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, OptionalWrapper, type OptionalWrapperProps, createSplitedContext, createSplittingContext, faas, getClient, useConstant, useFaas, type useFaasOptions, withFaasData };
|
package/dist/index.js
CHANGED
|
@@ -44,6 +44,48 @@ function createSplittingContext(defaultValue) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
var createSplitedContext = createSplittingContext;
|
|
47
|
+
function FaasDataWrapper({
|
|
48
|
+
action,
|
|
49
|
+
params,
|
|
50
|
+
fallback,
|
|
51
|
+
render,
|
|
52
|
+
children,
|
|
53
|
+
onDataChange,
|
|
54
|
+
data,
|
|
55
|
+
setData,
|
|
56
|
+
domain
|
|
57
|
+
}) {
|
|
58
|
+
const request = getClient(domain).useFaas(action, params, {
|
|
59
|
+
data,
|
|
60
|
+
setData
|
|
61
|
+
});
|
|
62
|
+
const [loaded, setLoaded] = react.useState(false);
|
|
63
|
+
react.useEffect(() => {
|
|
64
|
+
if (!loaded && !request.loading) setLoaded(true);
|
|
65
|
+
}, [request.loading]);
|
|
66
|
+
react.useEffect(() => {
|
|
67
|
+
if (onDataChange) onDataChange(request);
|
|
68
|
+
}, [JSON.stringify(request.data)]);
|
|
69
|
+
const child = react.useMemo(() => {
|
|
70
|
+
if (loaded) {
|
|
71
|
+
if (children) return react.cloneElement(children, request);
|
|
72
|
+
if (render) return render(request);
|
|
73
|
+
}
|
|
74
|
+
return fallback || null;
|
|
75
|
+
}, [
|
|
76
|
+
loaded,
|
|
77
|
+
request.action,
|
|
78
|
+
request.params,
|
|
79
|
+
request.data,
|
|
80
|
+
request.error,
|
|
81
|
+
request.loading
|
|
82
|
+
]);
|
|
83
|
+
return child;
|
|
84
|
+
}
|
|
85
|
+
FaasDataWrapper.whyDidYouRender = true;
|
|
86
|
+
function withFaasData(Component2, faasProps) {
|
|
87
|
+
return (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, { ...faasProps, children: /* @__PURE__ */ jsxRuntime.jsx(Component2, { ...props }) });
|
|
88
|
+
}
|
|
47
89
|
var clients = {};
|
|
48
90
|
function FaasReactClient({
|
|
49
91
|
domain,
|
|
@@ -157,49 +199,11 @@ function FaasReactClient({
|
|
|
157
199
|
};
|
|
158
200
|
}
|
|
159
201
|
useFaas2.whyDidYouRender = true;
|
|
160
|
-
function FaasDataWrapper2({
|
|
161
|
-
action,
|
|
162
|
-
params,
|
|
163
|
-
fallback,
|
|
164
|
-
render,
|
|
165
|
-
children,
|
|
166
|
-
onDataChange,
|
|
167
|
-
data,
|
|
168
|
-
setData
|
|
169
|
-
}) {
|
|
170
|
-
const request = useFaas2(action, params, {
|
|
171
|
-
data,
|
|
172
|
-
setData
|
|
173
|
-
});
|
|
174
|
-
const [loaded, setLoaded] = react.useState(false);
|
|
175
|
-
react.useEffect(() => {
|
|
176
|
-
if (!loaded && !request.loading) setLoaded(true);
|
|
177
|
-
}, [request.loading]);
|
|
178
|
-
react.useEffect(() => {
|
|
179
|
-
if (onDataChange) onDataChange(request);
|
|
180
|
-
}, [JSON.stringify(request.data)]);
|
|
181
|
-
const child = react.useMemo(() => {
|
|
182
|
-
if (loaded) {
|
|
183
|
-
if (children) return react.cloneElement(children, request);
|
|
184
|
-
if (render) return render(request);
|
|
185
|
-
}
|
|
186
|
-
return fallback || null;
|
|
187
|
-
}, [
|
|
188
|
-
loaded,
|
|
189
|
-
request.action,
|
|
190
|
-
request.params,
|
|
191
|
-
request.data,
|
|
192
|
-
request.error,
|
|
193
|
-
request.loading
|
|
194
|
-
]);
|
|
195
|
-
return child;
|
|
196
|
-
}
|
|
197
|
-
FaasDataWrapper2.whyDidYouRender = true;
|
|
198
202
|
const reactClient = {
|
|
199
203
|
id: client.id,
|
|
200
204
|
faas: faas2,
|
|
201
205
|
useFaas: useFaas2,
|
|
202
|
-
FaasDataWrapper:
|
|
206
|
+
FaasDataWrapper: (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, { domain, ...props })
|
|
203
207
|
};
|
|
204
208
|
clients[domain] = reactClient;
|
|
205
209
|
return reactClient;
|
|
@@ -220,16 +224,6 @@ async function faas(action, params) {
|
|
|
220
224
|
function useFaas(action, defaultParams, options) {
|
|
221
225
|
return getClient().useFaas(action, defaultParams, options);
|
|
222
226
|
}
|
|
223
|
-
function FaasDataWrapper(props) {
|
|
224
|
-
const [client, setClient] = react.useState();
|
|
225
|
-
react.useEffect(() => {
|
|
226
|
-
if (client) return;
|
|
227
|
-
setClient(getClient());
|
|
228
|
-
}, []);
|
|
229
|
-
if (!client) return props.fallback || null;
|
|
230
|
-
return /* @__PURE__ */ jsxRuntime.jsx(client.FaasDataWrapper, { ...props });
|
|
231
|
-
}
|
|
232
|
-
FaasDataWrapper.whyDidYouRender = true;
|
|
233
227
|
var ErrorBoundary = class extends react.Component {
|
|
234
228
|
constructor(props) {
|
|
235
229
|
super(props);
|
|
@@ -284,3 +278,4 @@ exports.faas = faas;
|
|
|
284
278
|
exports.getClient = getClient;
|
|
285
279
|
exports.useConstant = useConstant;
|
|
286
280
|
exports.useFaas = useFaas;
|
|
281
|
+
exports.withFaasData = withFaasData;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useRef, createContext, useState, useEffect,
|
|
1
|
+
import { useRef, createContext, useState, useEffect, useMemo, cloneElement, Component, useContext, useCallback } from 'react';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { FaasBrowserClient } from '@faasjs/browser';
|
|
4
4
|
|
|
@@ -42,6 +42,48 @@ function createSplittingContext(defaultValue) {
|
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
var createSplitedContext = createSplittingContext;
|
|
45
|
+
function FaasDataWrapper({
|
|
46
|
+
action,
|
|
47
|
+
params,
|
|
48
|
+
fallback,
|
|
49
|
+
render,
|
|
50
|
+
children,
|
|
51
|
+
onDataChange,
|
|
52
|
+
data,
|
|
53
|
+
setData,
|
|
54
|
+
domain
|
|
55
|
+
}) {
|
|
56
|
+
const request = getClient(domain).useFaas(action, params, {
|
|
57
|
+
data,
|
|
58
|
+
setData
|
|
59
|
+
});
|
|
60
|
+
const [loaded, setLoaded] = useState(false);
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (!loaded && !request.loading) setLoaded(true);
|
|
63
|
+
}, [request.loading]);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (onDataChange) onDataChange(request);
|
|
66
|
+
}, [JSON.stringify(request.data)]);
|
|
67
|
+
const child = useMemo(() => {
|
|
68
|
+
if (loaded) {
|
|
69
|
+
if (children) return cloneElement(children, request);
|
|
70
|
+
if (render) return render(request);
|
|
71
|
+
}
|
|
72
|
+
return fallback || null;
|
|
73
|
+
}, [
|
|
74
|
+
loaded,
|
|
75
|
+
request.action,
|
|
76
|
+
request.params,
|
|
77
|
+
request.data,
|
|
78
|
+
request.error,
|
|
79
|
+
request.loading
|
|
80
|
+
]);
|
|
81
|
+
return child;
|
|
82
|
+
}
|
|
83
|
+
FaasDataWrapper.whyDidYouRender = true;
|
|
84
|
+
function withFaasData(Component2, faasProps) {
|
|
85
|
+
return (props) => /* @__PURE__ */ jsx(FaasDataWrapper, { ...faasProps, children: /* @__PURE__ */ jsx(Component2, { ...props }) });
|
|
86
|
+
}
|
|
45
87
|
var clients = {};
|
|
46
88
|
function FaasReactClient({
|
|
47
89
|
domain,
|
|
@@ -155,49 +197,11 @@ function FaasReactClient({
|
|
|
155
197
|
};
|
|
156
198
|
}
|
|
157
199
|
useFaas2.whyDidYouRender = true;
|
|
158
|
-
function FaasDataWrapper2({
|
|
159
|
-
action,
|
|
160
|
-
params,
|
|
161
|
-
fallback,
|
|
162
|
-
render,
|
|
163
|
-
children,
|
|
164
|
-
onDataChange,
|
|
165
|
-
data,
|
|
166
|
-
setData
|
|
167
|
-
}) {
|
|
168
|
-
const request = useFaas2(action, params, {
|
|
169
|
-
data,
|
|
170
|
-
setData
|
|
171
|
-
});
|
|
172
|
-
const [loaded, setLoaded] = useState(false);
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
if (!loaded && !request.loading) setLoaded(true);
|
|
175
|
-
}, [request.loading]);
|
|
176
|
-
useEffect(() => {
|
|
177
|
-
if (onDataChange) onDataChange(request);
|
|
178
|
-
}, [JSON.stringify(request.data)]);
|
|
179
|
-
const child = useMemo(() => {
|
|
180
|
-
if (loaded) {
|
|
181
|
-
if (children) return cloneElement(children, request);
|
|
182
|
-
if (render) return render(request);
|
|
183
|
-
}
|
|
184
|
-
return fallback || null;
|
|
185
|
-
}, [
|
|
186
|
-
loaded,
|
|
187
|
-
request.action,
|
|
188
|
-
request.params,
|
|
189
|
-
request.data,
|
|
190
|
-
request.error,
|
|
191
|
-
request.loading
|
|
192
|
-
]);
|
|
193
|
-
return child;
|
|
194
|
-
}
|
|
195
|
-
FaasDataWrapper2.whyDidYouRender = true;
|
|
196
200
|
const reactClient = {
|
|
197
201
|
id: client.id,
|
|
198
202
|
faas: faas2,
|
|
199
203
|
useFaas: useFaas2,
|
|
200
|
-
FaasDataWrapper:
|
|
204
|
+
FaasDataWrapper: (props) => /* @__PURE__ */ jsx(FaasDataWrapper, { domain, ...props })
|
|
201
205
|
};
|
|
202
206
|
clients[domain] = reactClient;
|
|
203
207
|
return reactClient;
|
|
@@ -218,16 +222,6 @@ async function faas(action, params) {
|
|
|
218
222
|
function useFaas(action, defaultParams, options) {
|
|
219
223
|
return getClient().useFaas(action, defaultParams, options);
|
|
220
224
|
}
|
|
221
|
-
function FaasDataWrapper(props) {
|
|
222
|
-
const [client, setClient] = useState();
|
|
223
|
-
useEffect(() => {
|
|
224
|
-
if (client) return;
|
|
225
|
-
setClient(getClient());
|
|
226
|
-
}, []);
|
|
227
|
-
if (!client) return props.fallback || null;
|
|
228
|
-
return /* @__PURE__ */ jsx(client.FaasDataWrapper, { ...props });
|
|
229
|
-
}
|
|
230
|
-
FaasDataWrapper.whyDidYouRender = true;
|
|
231
225
|
var ErrorBoundary = class extends Component {
|
|
232
226
|
constructor(props) {
|
|
233
227
|
super(props);
|
|
@@ -272,4 +266,4 @@ var OptionalWrapper = ({ condition, Wrapper, wrapperProps, children }) => {
|
|
|
272
266
|
};
|
|
273
267
|
OptionalWrapper.whyDidYouRender = true;
|
|
274
268
|
|
|
275
|
-
export { ErrorBoundary, FaasDataWrapper, FaasReactClient, OptionalWrapper, createSplitedContext, createSplittingContext, faas, getClient, useConstant, useFaas };
|
|
269
|
+
export { ErrorBoundary, FaasDataWrapper, FaasReactClient, OptionalWrapper, createSplitedContext, createSplittingContext, faas, getClient, useConstant, useFaas, withFaasData };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@faasjs/browser": "2.
|
|
37
|
+
"@faasjs/browser": "2.8.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": "*"
|