@faasjs/react 8.0.0-beta.3 → 8.0.0-beta.30

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.cjs DELETED
@@ -1,769 +0,0 @@
1
- 'use strict';
2
-
3
- var browser = require('@faasjs/browser');
4
- var react = require('react');
5
- var jsxRuntime = require('react/jsx-runtime');
6
-
7
- // src/client.tsx
8
- var AsyncFunction = (async () => {
9
- }).constructor;
10
- function equal(a, b) {
11
- if (a === b) return true;
12
- if ((a === null || a === void 0) && (b === null || b === void 0))
13
- return true;
14
- if (typeof a !== typeof b) return false;
15
- if (a === null || a === void 0 || b === null || b === void 0)
16
- return false;
17
- const ctor = a.constructor;
18
- if (ctor !== b.constructor) return false;
19
- switch (ctor) {
20
- case String:
21
- case Boolean:
22
- return a === b;
23
- case Number:
24
- return Number.isNaN(a) && Number.isNaN(b) || a === b;
25
- case Array: {
26
- if (a.length !== b.length) return false;
27
- for (let i = 0; i < a.length; i++) {
28
- if (!equal(a[i], b[i])) return false;
29
- }
30
- return true;
31
- }
32
- case Date:
33
- return a.getTime() === b.getTime();
34
- case RegExp:
35
- case Function:
36
- case AsyncFunction:
37
- return a.toString() === b.toString();
38
- case Map:
39
- case Set:
40
- return equal(Array.from(a), Array.from(b));
41
- case Promise:
42
- return a === b;
43
- case Object: {
44
- for (const key of /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)]))
45
- if (!equal(a[key], b[key])) return false;
46
- return true;
47
- }
48
- default:
49
- throw Error(`Unsupported type: ${ctor}`);
50
- }
51
- }
52
- function useEqualMemoize(value) {
53
- const ref = react.useRef(value);
54
- const signalRef = react.useRef(0);
55
- if (!equal(value, ref.current)) {
56
- ref.current = value;
57
- signalRef.current += 1;
58
- }
59
- return react.useMemo(() => ref.current, [signalRef.current]);
60
- }
61
- function useEqualEffect(callback, dependencies) {
62
- return react.useEffect(callback, useEqualMemoize(dependencies));
63
- }
64
- function useEqualMemo(callback, dependencies) {
65
- return react.useMemo(callback, useEqualMemoize(dependencies));
66
- }
67
- function useEqualCallback(callback, dependencies) {
68
- return react.useCallback(
69
- (...args) => callback(...args),
70
- useEqualMemoize(dependencies)
71
- );
72
- }
73
- var fixedForwardRef = react.forwardRef;
74
- var FaasDataWrapper = fixedForwardRef(
75
- (props, ref) => {
76
- const request = getClient(props.baseUrl).useFaas(
77
- props.action,
78
- props.params,
79
- {
80
- data: props.data,
81
- setData: props.setData
82
- }
83
- );
84
- const [loaded, setLoaded] = react.useState(false);
85
- react.useImperativeHandle(ref, () => request, [request]);
86
- useEqualEffect(() => {
87
- if (!request.loading) setLoaded((prev) => prev === false ? true : prev);
88
- }, [request.loading]);
89
- useEqualEffect(() => {
90
- if (props.onDataChange) props.onDataChange(request);
91
- }, [request.data]);
92
- const child = useEqualMemo(() => {
93
- if (loaded) {
94
- if (props.children) return react.cloneElement(props.children, request);
95
- if (props.render) return props.render(request);
96
- }
97
- return props.fallback || null;
98
- }, [
99
- loaded,
100
- request.action,
101
- request.params,
102
- request.data,
103
- request.error,
104
- request.loading
105
- ]);
106
- return child;
107
- }
108
- );
109
- Object.assign(FaasDataWrapper, {
110
- displayName: "FaasDataWrapper"
111
- });
112
- function withFaasData(Component2, faasProps) {
113
- return (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, { ...faasProps, children: /* @__PURE__ */ jsxRuntime.jsx(Component2, { ...props }) });
114
- }
115
-
116
- // src/faas.ts
117
- async function faas(action, params, options) {
118
- const client = getClient(options?.baseUrl);
119
- if (client.onError)
120
- return client.browserClient.action(action, params, options).catch(async (res) => {
121
- await client.onError(action, params)(res);
122
- return Promise.reject(res);
123
- });
124
- return client.browserClient.action(action, params, options);
125
- }
126
- function useFaas(action, defaultParams, options = {}) {
127
- const [loading, setLoading] = react.useState(true);
128
- const [data, setData] = react.useState();
129
- const [error, setError] = react.useState();
130
- const [params, setParams] = react.useState(defaultParams);
131
- const [reloadTimes, setReloadTimes] = react.useState(0);
132
- const [fails, setFails] = react.useState(0);
133
- const [skip, setSkip] = react.useState(
134
- typeof options.skip === "function" ? options.skip(defaultParams) : options.skip
135
- );
136
- const promiseRef = react.useRef(null);
137
- const controllerRef = react.useRef(null);
138
- const pendingReloadsRef = react.useRef(/* @__PURE__ */ new Map());
139
- const reloadCounterRef = react.useRef(0);
140
- useEqualEffect(() => {
141
- setSkip(
142
- typeof options.skip === "function" ? options.skip(params) : options.skip
143
- );
144
- }, [typeof options.skip === "function" ? params : options.skip]);
145
- useEqualEffect(() => {
146
- if (!equal(defaultParams, params)) {
147
- setParams(defaultParams);
148
- }
149
- }, [defaultParams]);
150
- useEqualEffect(() => {
151
- if (!action || skip) {
152
- setLoading(false);
153
- return;
154
- }
155
- setLoading(true);
156
- controllerRef.current = new AbortController();
157
- const client = getClient(options.baseUrl);
158
- function send() {
159
- const request = client.faas(
160
- action,
161
- options.params || params,
162
- { signal: controllerRef.current.signal }
163
- );
164
- promiseRef.current = request;
165
- request.then((r) => {
166
- setFails(0);
167
- setError(null);
168
- options.setData ? options.setData(r.data) : setData(r.data);
169
- setLoading(false);
170
- for (const { resolve } of pendingReloadsRef.current.values())
171
- resolve(r.data);
172
- pendingReloadsRef.current.clear();
173
- }).catch(async (e) => {
174
- if (typeof e?.message === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
175
- return;
176
- if (!fails && typeof e?.message === "string" && e.message.indexOf("Failed to fetch") >= 0) {
177
- console.warn(`FaasReactClient: ${e.message} retry...`);
178
- setFails(1);
179
- return send();
180
- }
181
- let error2 = e;
182
- if (client.onError)
183
- try {
184
- await client.onError(action, params)(e);
185
- } catch (newError) {
186
- error2 = newError;
187
- }
188
- setError(error2);
189
- setLoading(false);
190
- for (const { reject } of pendingReloadsRef.current.values())
191
- reject(error2);
192
- pendingReloadsRef.current.clear();
193
- return;
194
- });
195
- }
196
- if (options.debounce) {
197
- const timeout = setTimeout(send, options.debounce);
198
- return () => {
199
- clearTimeout(timeout);
200
- controllerRef.current?.abort();
201
- setLoading(false);
202
- };
203
- }
204
- send();
205
- return () => {
206
- controllerRef.current?.abort();
207
- setLoading(false);
208
- };
209
- }, [action, options.params || params, reloadTimes, skip]);
210
- const reload = useEqualCallback(
211
- (params2) => {
212
- if (skip) setSkip(false);
213
- if (params2) setParams(params2);
214
- const reloadCounter = ++reloadCounterRef.current;
215
- setReloadTimes((prev) => prev + 1);
216
- return new Promise((resolve, reject) => {
217
- pendingReloadsRef.current.set(reloadCounter, { resolve, reject });
218
- setReloadTimes((prev) => prev + 1);
219
- });
220
- },
221
- [params, skip]
222
- );
223
- return {
224
- action,
225
- params,
226
- loading,
227
- data: options.data || data,
228
- reloadTimes,
229
- error,
230
- promise: promiseRef.current,
231
- reload,
232
- setData: options.setData || setData,
233
- setLoading,
234
- setPromise: (newPromise) => typeof newPromise === "function" ? newPromise(promiseRef.current) : promiseRef.current = newPromise,
235
- setError
236
- };
237
- }
238
- var clients = {};
239
- function FaasReactClient({ baseUrl, options, onError } = {
240
- baseUrl: "/"
241
- }) {
242
- const client = new browser.FaasBrowserClient(baseUrl, options);
243
- const reactClient = {
244
- id: client.id,
245
- faas: async (action, params, options2) => faas(action, params, { baseUrl, ...options2 }),
246
- useFaas: (action, defaultParams, options2) => useFaas(action, defaultParams, { baseUrl, ...options2 }),
247
- FaasDataWrapper: (props) => /* @__PURE__ */ jsxRuntime.jsx(FaasDataWrapper, { baseUrl, ...props }),
248
- onError,
249
- browserClient: client
250
- };
251
- clients[baseUrl] = reactClient;
252
- return reactClient;
253
- }
254
- function getClient(host) {
255
- const client = clients[host || Object.keys(clients)[0]];
256
- if (!client) {
257
- console.warn("FaasReactClient is not initialized manually, use default.");
258
- return FaasReactClient();
259
- }
260
- return client;
261
- }
262
- function useConstant(fn) {
263
- const ref = react.useRef(null);
264
- if (!ref.current) {
265
- ref.current = { v: fn() };
266
- }
267
- return ref.current.v;
268
- }
269
- var ErrorBoundary = class extends react.Component {
270
- static displayName = "ErrorBoundary";
271
- constructor(props) {
272
- super(props);
273
- this.state = {
274
- error: void 0,
275
- info: { componentStack: "" }
276
- };
277
- }
278
- componentDidCatch(error, info) {
279
- this.setState({
280
- error,
281
- info
282
- });
283
- }
284
- render() {
285
- const errorMessage = (this.state.error || "").toString();
286
- const errorDescription = this.state.info?.componentStack ? this.state.info.componentStack : null;
287
- if (this.state.error) {
288
- if (this.props.onError)
289
- this.props.onError(this.state.error, this.state.info);
290
- if (this.props.errorChildren)
291
- return react.cloneElement(this.props.errorChildren, {
292
- error: this.state.error,
293
- info: this.state.info,
294
- errorMessage,
295
- errorDescription
296
- });
297
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
298
- /* @__PURE__ */ jsxRuntime.jsx("p", { children: errorMessage }),
299
- /* @__PURE__ */ jsxRuntime.jsx("pre", { children: errorDescription })
300
- ] });
301
- }
302
- return this.props.children;
303
- }
304
- };
305
- function useStateRef(initialValue) {
306
- const [state, setState] = react.useState(initialValue ?? null);
307
- const ref = react.useRef(state);
308
- react.useEffect(() => {
309
- ref.current = state;
310
- }, [state]);
311
- return [state, setState, ref];
312
- }
313
- function useSplittingState(initialStates) {
314
- const states = {};
315
- for (const key of Object.keys(initialStates)) {
316
- const state = react.useState(initialStates[key]);
317
- Object.assign(states, {
318
- [key]: state[0],
319
- [`set${String(key).charAt(0).toUpperCase()}${String(key).slice(1)}`]: state[1]
320
- });
321
- }
322
- return states;
323
- }
324
- function createSplittingContext(defaultValue) {
325
- const keys = Array.isArray(defaultValue) ? defaultValue : Object.keys(defaultValue);
326
- const defaultValues = Array.isArray(defaultValue) ? keys.reduce(
327
- (prev, cur) => {
328
- prev[cur] = null;
329
- return prev;
330
- },
331
- {}
332
- ) : defaultValue;
333
- const contexts = {};
334
- for (const key of keys) contexts[key] = react.createContext(defaultValues[key]);
335
- function Provider(props) {
336
- const states = props.initializeStates ? useSplittingState(props.initializeStates) : {};
337
- let children = props.memo ? useEqualMemo(
338
- () => props.children,
339
- props.memo === true ? [] : props.memo
340
- ) : props.children;
341
- for (const key of keys) {
342
- const Context = contexts[key];
343
- const value = props.value?.[key] ?? states[key] ?? defaultValues[key];
344
- children = /* @__PURE__ */ jsxRuntime.jsx(Context.Provider, { value, children });
345
- }
346
- return children;
347
- }
348
- Provider.displayName = "SplittingContextProvider";
349
- function use() {
350
- return useConstant(() => {
351
- const obj = /* @__PURE__ */ Object.create(null);
352
- for (const key of Object.keys(contexts)) {
353
- Object.defineProperty(obj, key, {
354
- get: () => {
355
- if (!contexts[key]) {
356
- throw new Error(`Context for key "${key}" is undefined`);
357
- }
358
- return react.useContext(contexts[key]);
359
- }
360
- });
361
- }
362
- return Object.freeze(obj);
363
- });
364
- }
365
- return {
366
- Provider,
367
- use
368
- };
369
- }
370
-
371
- // src/Form/context.tsx
372
- var FormContext = createSplittingContext([
373
- "items",
374
- "onSubmit",
375
- "Elements",
376
- "lang",
377
- "rules",
378
- "submitting",
379
- "setSubmitting",
380
- "values",
381
- "setValues",
382
- "errors",
383
- "setErrors",
384
- "valuesRef"
385
- ]);
386
- var FormContextProvider = FormContext.Provider;
387
- var useFormContext = FormContext.use;
388
- function processValue(input, rules) {
389
- switch (rules?.type) {
390
- case "number":
391
- return Number(input);
392
- case "string":
393
- return String(input);
394
- default:
395
- return input;
396
- }
397
- }
398
- function FormInput({
399
- name,
400
- rules,
401
- ...rest
402
- }) {
403
- const { Elements, values, setValues } = useFormContext();
404
- const value = values?.[name];
405
- if (rest.Input) {
406
- return /* @__PURE__ */ jsxRuntime.jsx(
407
- rest.Input,
408
- {
409
- name,
410
- value,
411
- onChange: (v) => setValues((prev) => ({
412
- ...prev,
413
- [name]: processValue(v, rules)
414
- })),
415
- ...rest.props
416
- }
417
- );
418
- }
419
- return /* @__PURE__ */ jsxRuntime.jsx(
420
- Elements.Input,
421
- {
422
- name,
423
- value,
424
- onChange: (v) => setValues((prev) => ({
425
- ...prev,
426
- [name]: processValue(v, rules)
427
- })),
428
- ...rest.props
429
- }
430
- );
431
- }
432
- FormInput.displayName = "FormInput";
433
- function FormItem(props) {
434
- const { Elements, errors } = useFormContext();
435
- const Label = props.label?.Label ?? Elements.Label;
436
- return /* @__PURE__ */ jsxRuntime.jsx(Label, { name: props.name, ...props.label, error: errors[props.name], children: /* @__PURE__ */ jsxRuntime.jsx(FormInput, { name: props.name, rules: props.rules, ...props.input }) });
437
- }
438
- FormItem.displayName = "FormItem";
439
- function FormBody() {
440
- const { items } = useFormContext();
441
- return items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(FormItem, { ...item }, item.name));
442
- }
443
- FormBody.displayName = "FormBody";
444
- var FormButtonElement = react.forwardRef(({ children, submit, submitting, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
445
- "button",
446
- {
447
- type: "button",
448
- disabled: submitting,
449
- onClick: submit,
450
- ...props,
451
- ref,
452
- children
453
- }
454
- ));
455
- FormButtonElement.displayName = "FormButtonElement";
456
- var FormInputElement = react.forwardRef(({ onChange, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx("input", { ...props, onChange: (e) => onChange(e.target.value), ref }));
457
- FormInputElement.displayName = "FormInputElement";
458
- var FormLabelElement = ({
459
- name,
460
- title,
461
- description,
462
- error,
463
- children
464
- }) => {
465
- return /* @__PURE__ */ jsxRuntime.jsxs("label", { children: [
466
- title ?? name,
467
- children,
468
- description,
469
- error && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "red" }, children: error.message })
470
- ] });
471
- };
472
- FormLabelElement.displayName = "FormLabelElement";
473
-
474
- // src/Form/elements/index.ts
475
- var FormDefaultElements = {
476
- Label: FormLabelElement,
477
- Input: FormInputElement,
478
- Button: FormButtonElement
479
- };
480
-
481
- // src/Form/rules.ts
482
- var FormDefaultRules = {
483
- required: async (value, _, lang) => {
484
- if (value === null || value === void 0 || value === "" || Number.isNaN(value)) {
485
- throw Error(lang?.required);
486
- }
487
- },
488
- type: async (value, options, lang) => {
489
- switch (options) {
490
- case "string":
491
- if (typeof value !== "string") throw Error(lang?.string);
492
- break;
493
- case "number":
494
- if (Number.isNaN(Number(value))) throw Error(lang?.number);
495
- break;
496
- }
497
- },
498
- custom: async (value, options) => {
499
- return options(value);
500
- }
501
- };
502
- async function validValues(rules, items, values, lang) {
503
- const errors = {};
504
- for (const item of items) {
505
- const value = values[item.name];
506
- const rulesOptions = item.rules;
507
- if (rulesOptions) {
508
- for (const [name, options] of Object.entries(rulesOptions)) {
509
- try {
510
- await rules[name](value, options, lang);
511
- } catch (error) {
512
- errors[item.name] = error;
513
- break;
514
- }
515
- }
516
- }
517
- }
518
- return errors;
519
- }
520
- function FormFooter() {
521
- const {
522
- submitting,
523
- setSubmitting,
524
- onSubmit,
525
- valuesRef,
526
- Elements,
527
- items,
528
- setErrors,
529
- lang,
530
- rules
531
- } = useFormContext();
532
- const handleSubmit = react.useCallback(async () => {
533
- setSubmitting(true);
534
- setErrors({});
535
- const errors = await validValues(rules, items, valuesRef.current, lang);
536
- if (Object.keys(errors).length) {
537
- setErrors(errors);
538
- setSubmitting(false);
539
- return;
540
- }
541
- onSubmit(valuesRef.current).finally(() => setSubmitting(false));
542
- }, [setSubmitting, setErrors, rules, items, lang, onSubmit]);
543
- const MemoizedButton = react.useMemo(
544
- () => /* @__PURE__ */ jsxRuntime.jsx(Elements.Button, { submitting, submit: handleSubmit, children: lang.submit }),
545
- [submitting, handleSubmit, lang.submit, Elements.Button]
546
- );
547
- return MemoizedButton;
548
- }
549
- FormFooter.displayName = "FormFooter";
550
-
551
- // src/Form/lang.ts
552
- var FormDefaultLang = {
553
- submit: "Submit",
554
- required: "This field is required",
555
- string: "This field must be a string",
556
- number: "This field must be a number"
557
- };
558
- function mergeValues(items, defaultValues = {}) {
559
- const values = {};
560
- for (const item of items)
561
- values[item.name] = defaultValues[item.name] ?? "";
562
- return values;
563
- }
564
- function FormContainer({
565
- defaultValues,
566
- Elements,
567
- rules,
568
- lang,
569
- items,
570
- ...props
571
- }) {
572
- const [values, setValues, valuesRef] = useStateRef(
573
- mergeValues(items, defaultValues)
574
- );
575
- return /* @__PURE__ */ jsxRuntime.jsxs(
576
- FormContextProvider,
577
- {
578
- initializeStates: {
579
- errors: {},
580
- submitting: false
581
- },
582
- value: {
583
- Elements: Object.assign(FormDefaultElements, Elements),
584
- lang: Object.assign(FormDefaultLang, lang),
585
- rules: Object.assign(FormDefaultRules, rules),
586
- items,
587
- values,
588
- setValues,
589
- valuesRef,
590
- ...props
591
- },
592
- memo: true,
593
- children: [
594
- /* @__PURE__ */ jsxRuntime.jsx(FormBody, {}),
595
- /* @__PURE__ */ jsxRuntime.jsx(FormFooter, {})
596
- ]
597
- }
598
- );
599
- }
600
- FormContainer.displayName = "FormContainer";
601
- function OptionalWrapper({
602
- condition,
603
- Wrapper,
604
- wrapperProps,
605
- children
606
- }) {
607
- if (condition) return /* @__PURE__ */ jsxRuntime.jsx(Wrapper, { ...wrapperProps, children });
608
- return children;
609
- }
610
- OptionalWrapper.displayName = "OptionalWrapper";
611
- function useFaasStream(action, defaultParams, options = {}) {
612
- const [loading, setLoading] = react.useState(true);
613
- const [data, setData] = react.useState(options.data || "");
614
- const [error, setError] = react.useState();
615
- const [params, setParams] = react.useState(defaultParams);
616
- const [reloadTimes, setReloadTimes] = react.useState(0);
617
- const [fails, setFails] = react.useState(0);
618
- const [skip, setSkip] = react.useState(
619
- typeof options.skip === "function" ? options.skip(defaultParams) : options.skip
620
- );
621
- const controllerRef = react.useRef(null);
622
- const pendingReloadsRef = react.useRef(/* @__PURE__ */ new Map());
623
- const reloadCounterRef = react.useRef(0);
624
- useEqualEffect(() => {
625
- setSkip(
626
- typeof options.skip === "function" ? options.skip(params) : options.skip
627
- );
628
- }, [typeof options.skip === "function" ? params : options.skip]);
629
- useEqualEffect(() => {
630
- if (!equal(defaultParams, params)) {
631
- setParams(defaultParams);
632
- }
633
- }, [defaultParams]);
634
- useEqualEffect(() => {
635
- if (!action || skip) {
636
- setLoading(false);
637
- return;
638
- }
639
- setLoading(true);
640
- setData("");
641
- controllerRef.current = new AbortController();
642
- const client = getClient(options.baseUrl);
643
- function send() {
644
- client.browserClient.action(action, options.params || params, {
645
- signal: controllerRef.current.signal,
646
- stream: true
647
- }).then(async (response) => {
648
- if (!response.body) {
649
- setError(new Error("Response body is null"));
650
- setLoading(false);
651
- return;
652
- }
653
- const reader = response.body.getReader();
654
- const decoder = new TextDecoder();
655
- let accumulatedText = "";
656
- try {
657
- while (true) {
658
- const { done, value } = await reader.read();
659
- if (done) break;
660
- accumulatedText += decoder.decode(value, { stream: true });
661
- setData(accumulatedText);
662
- }
663
- setFails(0);
664
- setError(null);
665
- setLoading(false);
666
- for (const { resolve } of pendingReloadsRef.current.values())
667
- resolve(accumulatedText);
668
- pendingReloadsRef.current.clear();
669
- } catch (readError) {
670
- reader.releaseLock();
671
- throw readError;
672
- }
673
- }).catch(async (e) => {
674
- if (typeof e?.message === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
675
- return;
676
- if (!fails && typeof e?.message === "string" && e.message.indexOf("Failed to fetch") >= 0) {
677
- console.warn(`FaasReactClient: ${e.message} retry...`);
678
- setFails(1);
679
- return send();
680
- }
681
- let error2 = e;
682
- if (client.onError)
683
- try {
684
- await client.onError(action, params)(e);
685
- } catch (newError) {
686
- error2 = newError;
687
- }
688
- setError(error2);
689
- setLoading(false);
690
- for (const { reject } of pendingReloadsRef.current.values())
691
- reject(error2);
692
- pendingReloadsRef.current.clear();
693
- return;
694
- });
695
- }
696
- if (options.debounce) {
697
- const timeout = setTimeout(send, options.debounce);
698
- return () => {
699
- clearTimeout(timeout);
700
- controllerRef.current?.abort();
701
- setLoading(false);
702
- };
703
- }
704
- send();
705
- return () => {
706
- controllerRef.current?.abort();
707
- setLoading(false);
708
- };
709
- }, [action, options.params || params, reloadTimes, skip]);
710
- const reload = useEqualCallback(
711
- (params2) => {
712
- if (skip) setSkip(false);
713
- if (params2) setParams(params2);
714
- const reloadCounter = ++reloadCounterRef.current;
715
- return new Promise((resolve, reject) => {
716
- pendingReloadsRef.current.set(reloadCounter, { resolve, reject });
717
- setReloadTimes((prev) => prev + 1);
718
- });
719
- },
720
- [params, skip]
721
- );
722
- return {
723
- action,
724
- params,
725
- loading,
726
- data: options.data || data,
727
- reloadTimes,
728
- error,
729
- reload,
730
- setData: options.setData || setData,
731
- setLoading,
732
- setError
733
- };
734
- }
735
- function usePrevious(value) {
736
- const ref = react.useRef(void 0);
737
- react.useEffect(() => {
738
- ref.current = value;
739
- });
740
- return ref.current;
741
- }
742
-
743
- exports.ErrorBoundary = ErrorBoundary;
744
- exports.FaasDataWrapper = FaasDataWrapper;
745
- exports.FaasReactClient = FaasReactClient;
746
- exports.Form = FormContainer;
747
- exports.FormContextProvider = FormContextProvider;
748
- exports.FormDefaultElements = FormDefaultElements;
749
- exports.FormDefaultLang = FormDefaultLang;
750
- exports.FormDefaultRules = FormDefaultRules;
751
- exports.FormItem = FormItem;
752
- exports.OptionalWrapper = OptionalWrapper;
753
- exports.createSplittingContext = createSplittingContext;
754
- exports.equal = equal;
755
- exports.faas = faas;
756
- exports.getClient = getClient;
757
- exports.useConstant = useConstant;
758
- exports.useEqualCallback = useEqualCallback;
759
- exports.useEqualEffect = useEqualEffect;
760
- exports.useEqualMemo = useEqualMemo;
761
- exports.useEqualMemoize = useEqualMemoize;
762
- exports.useFaas = useFaas;
763
- exports.useFaasStream = useFaasStream;
764
- exports.useFormContext = useFormContext;
765
- exports.usePrevious = usePrevious;
766
- exports.useSplittingState = useSplittingState;
767
- exports.useStateRef = useStateRef;
768
- exports.validValues = validValues;
769
- exports.withFaasData = withFaasData;