@faasjs/react 0.0.3-beta.95 → 0.0.3-beta.97
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.d.mts +75 -62
- package/dist/index.d.ts +75 -62
- package/dist/index.js +49 -45
- package/dist/index.mjs +50 -43
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,69 +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
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { ReactNode, ReactElement, Component } from 'react';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
error?: Error;
|
|
21
|
-
info?: {
|
|
22
|
-
componentStack?: string;
|
|
23
|
-
};
|
|
24
|
-
}> {
|
|
25
|
-
constructor(props: ErrorBoundaryProps);
|
|
26
|
-
componentDidCatch(error: Error | null, info: any): void;
|
|
27
|
-
render(): string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
|
|
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
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
/**
|
|
31
23
|
* Injects FaasData props.
|
|
32
24
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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>>
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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>>>
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
66
60
|
}
|
|
61
|
+
|
|
67
62
|
/**
|
|
68
63
|
* Before use faas, you should initialize a FaasReactClient.
|
|
69
64
|
*
|
|
@@ -107,7 +102,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
|
|
|
107
102
|
* })
|
|
108
103
|
* ```
|
|
109
104
|
*/
|
|
110
|
-
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>>>;
|
|
111
106
|
/**
|
|
112
107
|
* Request faas server with React hook
|
|
113
108
|
* @param action {string} action name
|
|
@@ -121,11 +116,7 @@ declare function faas<PathOrData extends FaasAction>(action: string | PathOrData
|
|
|
121
116
|
* }
|
|
122
117
|
* ```
|
|
123
118
|
*/
|
|
124
|
-
declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrData, defaultParams: FaasParams<PathOrData>, options?:
|
|
125
|
-
data?: FaasData<PathOrData>;
|
|
126
|
-
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
|
|
127
|
-
skip?: boolean;
|
|
128
|
-
}): 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>>;
|
|
129
120
|
/**
|
|
130
121
|
* A data wrapper for react components
|
|
131
122
|
* @returns {JSX.Element}
|
|
@@ -141,6 +132,28 @@ declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrD
|
|
|
141
132
|
* />
|
|
142
133
|
* ```
|
|
143
134
|
*/
|
|
144
|
-
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
|
+
}
|
|
145
158
|
|
|
146
|
-
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, 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.d.ts
CHANGED
|
@@ -1,69 +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
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import { ReactNode, ReactElement, Component } from 'react';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
error?: Error;
|
|
21
|
-
info?: {
|
|
22
|
-
componentStack?: string;
|
|
23
|
-
};
|
|
24
|
-
}> {
|
|
25
|
-
constructor(props: ErrorBoundaryProps);
|
|
26
|
-
componentDidCatch(error: Error | null, info: any): void;
|
|
27
|
-
render(): string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
|
|
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
|
|
28
20
|
}
|
|
29
21
|
|
|
30
22
|
/**
|
|
31
23
|
* Injects FaasData props.
|
|
32
24
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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>>
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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>>>
|
|
57
51
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
66
60
|
}
|
|
61
|
+
|
|
67
62
|
/**
|
|
68
63
|
* Before use faas, you should initialize a FaasReactClient.
|
|
69
64
|
*
|
|
@@ -107,7 +102,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
|
|
|
107
102
|
* })
|
|
108
103
|
* ```
|
|
109
104
|
*/
|
|
110
|
-
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>>>;
|
|
111
106
|
/**
|
|
112
107
|
* Request faas server with React hook
|
|
113
108
|
* @param action {string} action name
|
|
@@ -121,11 +116,7 @@ declare function faas<PathOrData extends FaasAction>(action: string | PathOrData
|
|
|
121
116
|
* }
|
|
122
117
|
* ```
|
|
123
118
|
*/
|
|
124
|
-
declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrData, defaultParams: FaasParams<PathOrData>, options?:
|
|
125
|
-
data?: FaasData<PathOrData>;
|
|
126
|
-
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>;
|
|
127
|
-
skip?: boolean;
|
|
128
|
-
}): 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>>;
|
|
129
120
|
/**
|
|
130
121
|
* A data wrapper for react components
|
|
131
122
|
* @returns {JSX.Element}
|
|
@@ -141,6 +132,28 @@ declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrD
|
|
|
141
132
|
* />
|
|
142
133
|
* ```
|
|
143
134
|
*/
|
|
144
|
-
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
|
+
}
|
|
145
158
|
|
|
146
|
-
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, 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,48 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var browser = require('@faasjs/browser');
|
|
4
3
|
var react = require('react');
|
|
4
|
+
var browser = require('@faasjs/browser');
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
|
|
7
|
-
// src/
|
|
8
|
-
var ErrorBoundary = class extends react.Component {
|
|
9
|
-
constructor(props) {
|
|
10
|
-
super(props);
|
|
11
|
-
this.state = {
|
|
12
|
-
error: void 0,
|
|
13
|
-
info: { componentStack: "" }
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
componentDidCatch(error, info) {
|
|
17
|
-
this.setState({
|
|
18
|
-
error,
|
|
19
|
-
info
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
render() {
|
|
23
|
-
var _a;
|
|
24
|
-
const errorMessage = (this.state.error || "").toString();
|
|
25
|
-
const errorDescription = ((_a = this.state.info) == null ? void 0 : _a.componentStack) ? this.state.info.componentStack : null;
|
|
26
|
-
if (this.state.error) {
|
|
27
|
-
if (this.props.onError)
|
|
28
|
-
this.props.onError(this.state.error, this.state.info);
|
|
29
|
-
if (this.props.errorChildren)
|
|
30
|
-
return react.cloneElement(this.props.errorChildren, {
|
|
31
|
-
error: this.state.error,
|
|
32
|
-
info: this.state.info,
|
|
33
|
-
errorMessage,
|
|
34
|
-
errorDescription
|
|
35
|
-
});
|
|
36
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
37
|
-
/* @__PURE__ */ jsxRuntime.jsx("p", { children: errorMessage }),
|
|
38
|
-
/* @__PURE__ */ jsxRuntime.jsx("pre", { children: errorDescription })
|
|
39
|
-
] });
|
|
40
|
-
}
|
|
41
|
-
return this.props.children;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/index.tsx
|
|
7
|
+
// src/client.tsx
|
|
46
8
|
var clients = {};
|
|
47
9
|
function FaasReactClient({
|
|
48
10
|
domain,
|
|
@@ -102,6 +64,14 @@ function FaasReactClient({
|
|
|
102
64
|
return Promise.reject(e);
|
|
103
65
|
}).finally(() => setLoading(false));
|
|
104
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
|
+
}
|
|
105
75
|
send();
|
|
106
76
|
return () => {
|
|
107
77
|
controller.abort();
|
|
@@ -118,6 +88,7 @@ function FaasReactClient({
|
|
|
118
88
|
params,
|
|
119
89
|
loading,
|
|
120
90
|
data: (options2 == null ? void 0 : options2.data) || data,
|
|
91
|
+
reloadTimes,
|
|
121
92
|
error,
|
|
122
93
|
promise,
|
|
123
94
|
async reload(params2) {
|
|
@@ -133,6 +104,7 @@ function FaasReactClient({
|
|
|
133
104
|
};
|
|
134
105
|
}
|
|
135
106
|
const reactClient = {
|
|
107
|
+
id: client.id,
|
|
136
108
|
faas: faas2,
|
|
137
109
|
useFaas: useFaas2,
|
|
138
110
|
FaasDataWrapper({
|
|
@@ -191,13 +163,45 @@ function FaasDataWrapper(props) {
|
|
|
191
163
|
}, []);
|
|
192
164
|
if (!client)
|
|
193
165
|
return props.fallback || null;
|
|
194
|
-
return
|
|
166
|
+
return /* @__PURE__ */ jsxRuntime.jsx(client.FaasDataWrapper, { ...props });
|
|
195
167
|
}
|
|
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
|
+
};
|
|
196
204
|
|
|
197
|
-
Object.defineProperty(exports, 'FaasBrowserClient', {
|
|
198
|
-
enumerable: true,
|
|
199
|
-
get: function () { return browser.FaasBrowserClient; }
|
|
200
|
-
});
|
|
201
205
|
exports.ErrorBoundary = ErrorBoundary;
|
|
202
206
|
exports.FaasDataWrapper = FaasDataWrapper;
|
|
203
207
|
exports.FaasReactClient = FaasReactClient;
|
package/dist/index.mjs
CHANGED
|
@@ -1,47 +1,8 @@
|
|
|
1
|
+
import { useState, useEffect, cloneElement, Component } from 'react';
|
|
1
2
|
import { FaasBrowserClient } from '@faasjs/browser';
|
|
2
|
-
|
|
3
|
-
import { Component, cloneElement, useState, useEffect, createElement } from 'react';
|
|
4
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
4
|
|
|
6
|
-
// src/
|
|
7
|
-
var ErrorBoundary = class extends Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
this.state = {
|
|
11
|
-
error: void 0,
|
|
12
|
-
info: { componentStack: "" }
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
componentDidCatch(error, info) {
|
|
16
|
-
this.setState({
|
|
17
|
-
error,
|
|
18
|
-
info
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
render() {
|
|
22
|
-
var _a;
|
|
23
|
-
const errorMessage = (this.state.error || "").toString();
|
|
24
|
-
const errorDescription = ((_a = this.state.info) == null ? void 0 : _a.componentStack) ? this.state.info.componentStack : null;
|
|
25
|
-
if (this.state.error) {
|
|
26
|
-
if (this.props.onError)
|
|
27
|
-
this.props.onError(this.state.error, this.state.info);
|
|
28
|
-
if (this.props.errorChildren)
|
|
29
|
-
return cloneElement(this.props.errorChildren, {
|
|
30
|
-
error: this.state.error,
|
|
31
|
-
info: this.state.info,
|
|
32
|
-
errorMessage,
|
|
33
|
-
errorDescription
|
|
34
|
-
});
|
|
35
|
-
return /* @__PURE__ */ jsxs("div", { children: [
|
|
36
|
-
/* @__PURE__ */ jsx("p", { children: errorMessage }),
|
|
37
|
-
/* @__PURE__ */ jsx("pre", { children: errorDescription })
|
|
38
|
-
] });
|
|
39
|
-
}
|
|
40
|
-
return this.props.children;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// src/index.tsx
|
|
5
|
+
// src/client.tsx
|
|
45
6
|
var clients = {};
|
|
46
7
|
function FaasReactClient({
|
|
47
8
|
domain,
|
|
@@ -101,6 +62,14 @@ function FaasReactClient({
|
|
|
101
62
|
return Promise.reject(e);
|
|
102
63
|
}).finally(() => setLoading(false));
|
|
103
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
|
+
}
|
|
104
73
|
send();
|
|
105
74
|
return () => {
|
|
106
75
|
controller.abort();
|
|
@@ -117,6 +86,7 @@ function FaasReactClient({
|
|
|
117
86
|
params,
|
|
118
87
|
loading,
|
|
119
88
|
data: (options2 == null ? void 0 : options2.data) || data,
|
|
89
|
+
reloadTimes,
|
|
120
90
|
error,
|
|
121
91
|
promise,
|
|
122
92
|
async reload(params2) {
|
|
@@ -132,6 +102,7 @@ function FaasReactClient({
|
|
|
132
102
|
};
|
|
133
103
|
}
|
|
134
104
|
const reactClient = {
|
|
105
|
+
id: client.id,
|
|
135
106
|
faas: faas2,
|
|
136
107
|
useFaas: useFaas2,
|
|
137
108
|
FaasDataWrapper({
|
|
@@ -190,7 +161,43 @@ function FaasDataWrapper(props) {
|
|
|
190
161
|
}, []);
|
|
191
162
|
if (!client)
|
|
192
163
|
return props.fallback || null;
|
|
193
|
-
return
|
|
164
|
+
return /* @__PURE__ */ jsx(client.FaasDataWrapper, { ...props });
|
|
194
165
|
}
|
|
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
|
+
}
|
|
201
|
+
};
|
|
195
202
|
|
|
196
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.97",
|
|
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.3-beta.
|
|
25
|
+
"@faasjs/browser": "0.0.3-beta.97"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "*"
|