@faasjs/react 0.0.3-beta.95 → 0.0.3-beta.96
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 +74 -62
- package/dist/index.d.ts +74 -62
- package/dist/index.js +48 -45
- package/dist/index.mjs +49 -43
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,69 +1,63 @@
|
|
|
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
|
+
data: Data
|
|
30
|
+
error: any
|
|
31
|
+
promise: Promise<Response<Data>>
|
|
32
|
+
reload(params?: Record<string, any>): Promise<Response<Data>>,
|
|
33
|
+
setData: React.Dispatch<React.SetStateAction<Data>>
|
|
34
|
+
setLoading: React.Dispatch<React.SetStateAction<boolean>>
|
|
35
|
+
setPromise: React.Dispatch<React.SetStateAction<Promise<Response<Data>>>>
|
|
36
|
+
setError: React.Dispatch<React.SetStateAction<any>>
|
|
45
37
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
38
|
+
|
|
39
|
+
type FaasDataWrapperProps<PathOrData extends FaasAction> = {
|
|
40
|
+
render?(args: FaasDataInjection<FaasData<PathOrData>>): JSX.Element | JSX.Element[]
|
|
41
|
+
children?: React.ReactElement<Partial<FaasDataInjection>>
|
|
42
|
+
fallback?: JSX.Element | false
|
|
43
|
+
action: string
|
|
44
|
+
params?: FaasParams<PathOrData>
|
|
45
|
+
onDataChange?(args: FaasDataInjection<FaasData<PathOrData>>): void
|
|
46
|
+
/** use custom data, should work with setData */
|
|
47
|
+
data?: FaasData<PathOrData>
|
|
48
|
+
/** use custom setData, should work with data */
|
|
49
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
57
50
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
|
|
52
|
+
type useFaasOptions<PathOrData extends FaasAction> = {
|
|
53
|
+
params?: FaasParams<PathOrData>
|
|
54
|
+
data?: FaasData<PathOrData>
|
|
55
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
56
|
+
skip?: boolean
|
|
57
|
+
/** send the last request after milliseconds */
|
|
58
|
+
debounce?: number
|
|
66
59
|
}
|
|
60
|
+
|
|
67
61
|
/**
|
|
68
62
|
* Before use faas, you should initialize a FaasReactClient.
|
|
69
63
|
*
|
|
@@ -107,7 +101,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
|
|
|
107
101
|
* })
|
|
108
102
|
* ```
|
|
109
103
|
*/
|
|
110
|
-
declare function faas<PathOrData extends FaasAction>(action: string | PathOrData, params: FaasParams<PathOrData>): Promise<Response<FaasData<PathOrData>>>;
|
|
104
|
+
declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrData, params: FaasParams$1<PathOrData>): Promise<Response$1<FaasData$1<PathOrData>>>;
|
|
111
105
|
/**
|
|
112
106
|
* Request faas server with React hook
|
|
113
107
|
* @param action {string} action name
|
|
@@ -121,11 +115,7 @@ declare function faas<PathOrData extends FaasAction>(action: string | PathOrData
|
|
|
121
115
|
* }
|
|
122
116
|
* ```
|
|
123
117
|
*/
|
|
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>>;
|
|
118
|
+
declare function useFaas<PathOrData extends FaasAction$1>(action: string | PathOrData, defaultParams: FaasParams$1<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<FaasData$1<PathOrData>>;
|
|
129
119
|
/**
|
|
130
120
|
* A data wrapper for react components
|
|
131
121
|
* @returns {JSX.Element}
|
|
@@ -141,6 +131,28 @@ declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrD
|
|
|
141
131
|
* />
|
|
142
132
|
* ```
|
|
143
133
|
*/
|
|
144
|
-
declare function FaasDataWrapper<PathOrData extends FaasAction>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
134
|
+
declare function FaasDataWrapper<PathOrData extends FaasAction$1>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
135
|
+
|
|
136
|
+
interface ErrorBoundaryProps {
|
|
137
|
+
children?: ReactNode;
|
|
138
|
+
onError?: (error: Error | null, info: any) => void;
|
|
139
|
+
errorChildren?: ReactElement<ErrorChildrenProps>;
|
|
140
|
+
}
|
|
141
|
+
type ErrorChildrenProps = {
|
|
142
|
+
error?: Error;
|
|
143
|
+
info?: any;
|
|
144
|
+
errorMessage?: string;
|
|
145
|
+
errorDescription?: string;
|
|
146
|
+
};
|
|
147
|
+
declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
148
|
+
error?: Error;
|
|
149
|
+
info?: {
|
|
150
|
+
componentStack?: string;
|
|
151
|
+
};
|
|
152
|
+
}> {
|
|
153
|
+
constructor(props: ErrorBoundaryProps);
|
|
154
|
+
componentDidCatch(error: Error | null, info: any): void;
|
|
155
|
+
render(): string | number | boolean | react_jsx_runtime.JSX.Element | Iterable<ReactNode>;
|
|
156
|
+
}
|
|
145
157
|
|
|
146
|
-
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasReactClient, FaasReactClientInstance, faas, getClient, useFaas };
|
|
158
|
+
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasReactClient, FaasReactClientInstance, faas, getClient, useFaas, useFaasOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,69 +1,63 @@
|
|
|
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
|
+
data: Data
|
|
30
|
+
error: any
|
|
31
|
+
promise: Promise<Response<Data>>
|
|
32
|
+
reload(params?: Record<string, any>): Promise<Response<Data>>,
|
|
33
|
+
setData: React.Dispatch<React.SetStateAction<Data>>
|
|
34
|
+
setLoading: React.Dispatch<React.SetStateAction<boolean>>
|
|
35
|
+
setPromise: React.Dispatch<React.SetStateAction<Promise<Response<Data>>>>
|
|
36
|
+
setError: React.Dispatch<React.SetStateAction<any>>
|
|
45
37
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
38
|
+
|
|
39
|
+
type FaasDataWrapperProps<PathOrData extends FaasAction> = {
|
|
40
|
+
render?(args: FaasDataInjection<FaasData<PathOrData>>): JSX.Element | JSX.Element[]
|
|
41
|
+
children?: React.ReactElement<Partial<FaasDataInjection>>
|
|
42
|
+
fallback?: JSX.Element | false
|
|
43
|
+
action: string
|
|
44
|
+
params?: FaasParams<PathOrData>
|
|
45
|
+
onDataChange?(args: FaasDataInjection<FaasData<PathOrData>>): void
|
|
46
|
+
/** use custom data, should work with setData */
|
|
47
|
+
data?: FaasData<PathOrData>
|
|
48
|
+
/** use custom setData, should work with data */
|
|
49
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
57
50
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
|
|
52
|
+
type useFaasOptions<PathOrData extends FaasAction> = {
|
|
53
|
+
params?: FaasParams<PathOrData>
|
|
54
|
+
data?: FaasData<PathOrData>
|
|
55
|
+
setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
|
|
56
|
+
skip?: boolean
|
|
57
|
+
/** send the last request after milliseconds */
|
|
58
|
+
debounce?: number
|
|
66
59
|
}
|
|
60
|
+
|
|
67
61
|
/**
|
|
68
62
|
* Before use faas, you should initialize a FaasReactClient.
|
|
69
63
|
*
|
|
@@ -107,7 +101,7 @@ declare function getClient(domain?: string): FaasReactClientInstance;
|
|
|
107
101
|
* })
|
|
108
102
|
* ```
|
|
109
103
|
*/
|
|
110
|
-
declare function faas<PathOrData extends FaasAction>(action: string | PathOrData, params: FaasParams<PathOrData>): Promise<Response<FaasData<PathOrData>>>;
|
|
104
|
+
declare function faas<PathOrData extends FaasAction$1>(action: string | PathOrData, params: FaasParams$1<PathOrData>): Promise<Response$1<FaasData$1<PathOrData>>>;
|
|
111
105
|
/**
|
|
112
106
|
* Request faas server with React hook
|
|
113
107
|
* @param action {string} action name
|
|
@@ -121,11 +115,7 @@ declare function faas<PathOrData extends FaasAction>(action: string | PathOrData
|
|
|
121
115
|
* }
|
|
122
116
|
* ```
|
|
123
117
|
*/
|
|
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>>;
|
|
118
|
+
declare function useFaas<PathOrData extends FaasAction$1>(action: string | PathOrData, defaultParams: FaasParams$1<PathOrData>, options?: useFaasOptions<PathOrData>): FaasDataInjection<FaasData$1<PathOrData>>;
|
|
129
119
|
/**
|
|
130
120
|
* A data wrapper for react components
|
|
131
121
|
* @returns {JSX.Element}
|
|
@@ -141,6 +131,28 @@ declare function useFaas<PathOrData extends FaasAction>(action: string | PathOrD
|
|
|
141
131
|
* />
|
|
142
132
|
* ```
|
|
143
133
|
*/
|
|
144
|
-
declare function FaasDataWrapper<PathOrData extends FaasAction>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
134
|
+
declare function FaasDataWrapper<PathOrData extends FaasAction$1>(props: FaasDataWrapperProps<PathOrData>): JSX.Element;
|
|
135
|
+
|
|
136
|
+
interface ErrorBoundaryProps {
|
|
137
|
+
children?: ReactNode;
|
|
138
|
+
onError?: (error: Error | null, info: any) => void;
|
|
139
|
+
errorChildren?: ReactElement<ErrorChildrenProps>;
|
|
140
|
+
}
|
|
141
|
+
type ErrorChildrenProps = {
|
|
142
|
+
error?: Error;
|
|
143
|
+
info?: any;
|
|
144
|
+
errorMessage?: string;
|
|
145
|
+
errorDescription?: string;
|
|
146
|
+
};
|
|
147
|
+
declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
|
|
148
|
+
error?: Error;
|
|
149
|
+
info?: {
|
|
150
|
+
componentStack?: string;
|
|
151
|
+
};
|
|
152
|
+
}> {
|
|
153
|
+
constructor(props: ErrorBoundaryProps);
|
|
154
|
+
componentDidCatch(error: Error | null, info: any): void;
|
|
155
|
+
render(): string | number | boolean | react_jsx_runtime.JSX.Element | Iterable<ReactNode>;
|
|
156
|
+
}
|
|
145
157
|
|
|
146
|
-
export { ErrorBoundary, ErrorBoundaryProps, ErrorChildrenProps, FaasDataInjection, FaasDataWrapper, FaasDataWrapperProps, FaasReactClient, FaasReactClientInstance, faas, getClient, useFaas };
|
|
158
|
+
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();
|
|
@@ -133,6 +103,7 @@ function FaasReactClient({
|
|
|
133
103
|
};
|
|
134
104
|
}
|
|
135
105
|
const reactClient = {
|
|
106
|
+
id: client.id,
|
|
136
107
|
faas: faas2,
|
|
137
108
|
useFaas: useFaas2,
|
|
138
109
|
FaasDataWrapper({
|
|
@@ -191,13 +162,45 @@ function FaasDataWrapper(props) {
|
|
|
191
162
|
}, []);
|
|
192
163
|
if (!client)
|
|
193
164
|
return props.fallback || null;
|
|
194
|
-
return
|
|
165
|
+
return /* @__PURE__ */ jsxRuntime.jsx(client.FaasDataWrapper, { ...props });
|
|
195
166
|
}
|
|
167
|
+
var ErrorBoundary = class extends react.Component {
|
|
168
|
+
constructor(props) {
|
|
169
|
+
super(props);
|
|
170
|
+
this.state = {
|
|
171
|
+
error: void 0,
|
|
172
|
+
info: { componentStack: "" }
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
componentDidCatch(error, info) {
|
|
176
|
+
this.setState({
|
|
177
|
+
error,
|
|
178
|
+
info
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
render() {
|
|
182
|
+
var _a;
|
|
183
|
+
const errorMessage = (this.state.error || "").toString();
|
|
184
|
+
const errorDescription = ((_a = this.state.info) == null ? void 0 : _a.componentStack) ? this.state.info.componentStack : null;
|
|
185
|
+
if (this.state.error) {
|
|
186
|
+
if (this.props.onError)
|
|
187
|
+
this.props.onError(this.state.error, this.state.info);
|
|
188
|
+
if (this.props.errorChildren)
|
|
189
|
+
return react.cloneElement(this.props.errorChildren, {
|
|
190
|
+
error: this.state.error,
|
|
191
|
+
info: this.state.info,
|
|
192
|
+
errorMessage,
|
|
193
|
+
errorDescription
|
|
194
|
+
});
|
|
195
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
196
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { children: errorMessage }),
|
|
197
|
+
/* @__PURE__ */ jsxRuntime.jsx("pre", { children: errorDescription })
|
|
198
|
+
] });
|
|
199
|
+
}
|
|
200
|
+
return this.props.children;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
196
203
|
|
|
197
|
-
Object.defineProperty(exports, 'FaasBrowserClient', {
|
|
198
|
-
enumerable: true,
|
|
199
|
-
get: function () { return browser.FaasBrowserClient; }
|
|
200
|
-
});
|
|
201
204
|
exports.ErrorBoundary = ErrorBoundary;
|
|
202
205
|
exports.FaasDataWrapper = FaasDataWrapper;
|
|
203
206
|
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();
|
|
@@ -132,6 +101,7 @@ function FaasReactClient({
|
|
|
132
101
|
};
|
|
133
102
|
}
|
|
134
103
|
const reactClient = {
|
|
104
|
+
id: client.id,
|
|
135
105
|
faas: faas2,
|
|
136
106
|
useFaas: useFaas2,
|
|
137
107
|
FaasDataWrapper({
|
|
@@ -190,7 +160,43 @@ function FaasDataWrapper(props) {
|
|
|
190
160
|
}, []);
|
|
191
161
|
if (!client)
|
|
192
162
|
return props.fallback || null;
|
|
193
|
-
return
|
|
163
|
+
return /* @__PURE__ */ jsx(client.FaasDataWrapper, { ...props });
|
|
194
164
|
}
|
|
165
|
+
var ErrorBoundary = class extends Component {
|
|
166
|
+
constructor(props) {
|
|
167
|
+
super(props);
|
|
168
|
+
this.state = {
|
|
169
|
+
error: void 0,
|
|
170
|
+
info: { componentStack: "" }
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
componentDidCatch(error, info) {
|
|
174
|
+
this.setState({
|
|
175
|
+
error,
|
|
176
|
+
info
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
render() {
|
|
180
|
+
var _a;
|
|
181
|
+
const errorMessage = (this.state.error || "").toString();
|
|
182
|
+
const errorDescription = ((_a = this.state.info) == null ? void 0 : _a.componentStack) ? this.state.info.componentStack : null;
|
|
183
|
+
if (this.state.error) {
|
|
184
|
+
if (this.props.onError)
|
|
185
|
+
this.props.onError(this.state.error, this.state.info);
|
|
186
|
+
if (this.props.errorChildren)
|
|
187
|
+
return cloneElement(this.props.errorChildren, {
|
|
188
|
+
error: this.state.error,
|
|
189
|
+
info: this.state.info,
|
|
190
|
+
errorMessage,
|
|
191
|
+
errorDescription
|
|
192
|
+
});
|
|
193
|
+
return /* @__PURE__ */ jsxs("div", { children: [
|
|
194
|
+
/* @__PURE__ */ jsx("p", { children: errorMessage }),
|
|
195
|
+
/* @__PURE__ */ jsx("pre", { children: errorDescription })
|
|
196
|
+
] });
|
|
197
|
+
}
|
|
198
|
+
return this.props.children;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
195
201
|
|
|
196
202
|
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.96",
|
|
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.96"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "*"
|