@faasjs/react 1.7.1 → 2.0.0

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 CHANGED
@@ -27,17 +27,6 @@ const client = FaasReactClient({
27
27
 
28
28
  2. Use [faas](#faas), [useFaas](#usefaas) or [FaasDataWrapper](#faasdatawrapper).
29
29
 
30
- ## Usage with [@preact/signal-react](https://github.com/preactjs/signals/blob/main/packages/react/README.md)
31
-
32
- 1. `npm i --save-dev @preact/signals-react-transform`
33
- 2. Add `@preact/signals-react-transform` to babel config:
34
- ```json
35
- {
36
- "plugins": [["module:@preact/signals-react-transform"]]
37
- }
38
- ```
39
- 3. Add `import '@preact/signals-react/auto'` to your test files.
40
-
41
30
  ## Classes
42
31
 
43
32
  - [ErrorBoundary](classes/ErrorBoundary.md)
@@ -60,7 +49,6 @@ const client = FaasReactClient({
60
49
  - [FaasReactClientOptions](type-aliases/FaasReactClientOptions.md)
61
50
  - [Options](type-aliases/Options.md)
62
51
  - [ResponseHeaders](type-aliases/ResponseHeaders.md)
63
- - [SignalOptions](type-aliases/SignalOptions.md)
64
52
  - [useFaasOptions](type-aliases/useFaasOptions.md)
65
53
 
66
54
  ## Functions
@@ -69,7 +57,5 @@ const client = FaasReactClient({
69
57
  - [FaasReactClient](functions/FaasReactClient.md)
70
58
  - [faas](functions/faas.md)
71
59
  - [getClient](functions/getClient.md)
72
- - [signal](functions/signal.md)
73
60
  - [useConstant](functions/useConstant.md)
74
61
  - [useFaas](functions/useFaas.md)
75
- - [useSignalState](functions/useSignalState.md)
package/dist/index.d.mts CHANGED
@@ -3,10 +3,7 @@ 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';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import { ReactNode, ReactElement, Component, SetStateAction } from 'react';
7
- import * as _preact_signals_core from '@preact/signals-core';
8
- export { batch, computed, effect, signal as originSignal } from '@preact/signals-react';
9
- export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
6
+ import { ReactNode, ReactElement, Component } from 'react';
10
7
 
11
8
  /**
12
9
  * Returns a constant value that is created by the given function.
@@ -40,7 +37,7 @@ type FaasDataInjection<Data = any> = {
40
37
  data: Data
41
38
  error: any
42
39
  promise: Promise<Response<Data>>
43
- reload(params?: Record<string, any>): void
40
+ reload(params?: Record<string, any>): Promise<Response<Data>>
44
41
  setData: React.Dispatch<React.SetStateAction<Data>>
45
42
  setLoading: React.Dispatch<React.SetStateAction<boolean>>
46
43
  setPromise: React.Dispatch<React.SetStateAction<Promise<Response<Data>>>>
@@ -181,44 +178,4 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
181
178
  render(): string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
182
179
  }
183
180
 
184
- type SignalOptions = {
185
- debugName?: string;
186
- };
187
- /**
188
- * Create a [signal](https://preactjs.com/guide/v10/signals) with options
189
- *
190
- * @param initialValue
191
- * @param options
192
- * @param options.debugName - debug name for signal, will print signal value to console.debug
193
- *
194
- * @example
195
- * ```ts
196
- * import { signal } from '@faasjs/react'
197
- *
198
- * const count = signal(0, { debugName: 'count' })
199
- *
200
- * count.value = 1
201
- * ```
202
- */
203
- declare function signal<T = any>(initialValue: any, options?: SignalOptions): _preact_signals_core.Signal<T>;
204
- /**
205
- * Create a [signal](https://preactjs.com/guide/v10/signals) like useState.
206
- *
207
- * ```tsx
208
- * import { useSignalState, useSignalEffect } from '@faasjs/react'
209
- *
210
- * function App () {
211
- * const [count, setCount] = useSignalState(0, { debugName: 'count' })
212
- *
213
- * useSignalEffect(() => console.log('count', count))
214
- *
215
- * return <div>
216
- * <button onClick={() => setCount(count + 1)}>+</button>
217
- * <span>{count}</span>
218
- * </div>
219
- * }
220
- * ```
221
- */
222
- declare function useSignalState<T = any>(initialValue: T, options?: SignalOptions): readonly [T, (changes: SetStateAction<T>) => void];
223
-
224
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useConstant, useFaas, type useFaasOptions, useSignalState };
181
+ export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, faas, getClient, useConstant, useFaas, type useFaasOptions };
package/dist/index.d.ts CHANGED
@@ -3,10 +3,7 @@ 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';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
- import { ReactNode, ReactElement, Component, SetStateAction } from 'react';
7
- import * as _preact_signals_core from '@preact/signals-core';
8
- export { batch, computed, effect, signal as originSignal } from '@preact/signals-react';
9
- export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
6
+ import { ReactNode, ReactElement, Component } from 'react';
10
7
 
11
8
  /**
12
9
  * Returns a constant value that is created by the given function.
@@ -40,7 +37,7 @@ type FaasDataInjection<Data = any> = {
40
37
  data: Data
41
38
  error: any
42
39
  promise: Promise<Response<Data>>
43
- reload(params?: Record<string, any>): void
40
+ reload(params?: Record<string, any>): Promise<Response<Data>>
44
41
  setData: React.Dispatch<React.SetStateAction<Data>>
45
42
  setLoading: React.Dispatch<React.SetStateAction<boolean>>
46
43
  setPromise: React.Dispatch<React.SetStateAction<Promise<Response<Data>>>>
@@ -181,44 +178,4 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, {
181
178
  render(): string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
182
179
  }
183
180
 
184
- type SignalOptions = {
185
- debugName?: string;
186
- };
187
- /**
188
- * Create a [signal](https://preactjs.com/guide/v10/signals) with options
189
- *
190
- * @param initialValue
191
- * @param options
192
- * @param options.debugName - debug name for signal, will print signal value to console.debug
193
- *
194
- * @example
195
- * ```ts
196
- * import { signal } from '@faasjs/react'
197
- *
198
- * const count = signal(0, { debugName: 'count' })
199
- *
200
- * count.value = 1
201
- * ```
202
- */
203
- declare function signal<T = any>(initialValue: any, options?: SignalOptions): _preact_signals_core.Signal<T>;
204
- /**
205
- * Create a [signal](https://preactjs.com/guide/v10/signals) like useState.
206
- *
207
- * ```tsx
208
- * import { useSignalState, useSignalEffect } from '@faasjs/react'
209
- *
210
- * function App () {
211
- * const [count, setCount] = useSignalState(0, { debugName: 'count' })
212
- *
213
- * useSignalEffect(() => console.log('count', count))
214
- *
215
- * return <div>
216
- * <button onClick={() => setCount(count + 1)}>+</button>
217
- * <span>{count}</span>
218
- * </div>
219
- * }
220
- * ```
221
- */
222
- declare function useSignalState<T = any>(initialValue: T, options?: SignalOptions): readonly [T, (changes: SetStateAction<T>) => void];
223
-
224
- export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, type SignalOptions, faas, getClient, signal, useConstant, useFaas, type useFaasOptions, useSignalState };
181
+ export { ErrorBoundary, type ErrorBoundaryProps, type ErrorChildrenProps, type FaasDataInjection, FaasDataWrapper, type FaasDataWrapperProps, FaasReactClient, type FaasReactClientInstance, type FaasReactClientOptions, faas, getClient, useConstant, useFaas, type useFaasOptions };
package/dist/index.js CHANGED
@@ -3,8 +3,6 @@
3
3
  var react = require('react');
4
4
  var browser = require('@faasjs/browser');
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
- var signalsReact = require('@preact/signals-react');
7
- var runtime = require('@preact/signals-react/runtime');
8
6
 
9
7
  // src/constant.ts
10
8
  function useConstant(fn) {
@@ -68,10 +66,11 @@ function FaasReactClient({
68
66
  { signal: controller.signal }
69
67
  );
70
68
  setPromise(request);
71
- request.then(
72
- (r) => (options2 == null ? void 0 : options2.setData) ? options2.setData(r.data) : setData(r.data)
73
- ).catch(async (e) => {
74
- if ((e == null ? void 0 : e.message) === "The user aborted a request." || (e == null ? void 0 : e.message) === "Aborted")
69
+ request.then((r) => {
70
+ (options2 == null ? void 0 : options2.setData) ? options2.setData(r.data) : setData(r.data);
71
+ setLoading(false);
72
+ }).catch(async (e) => {
73
+ if (typeof (e == null ? void 0 : e.message) === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
75
74
  return;
76
75
  if (!fails && typeof (e == null ? void 0 : e.message) === "string" && e.message.indexOf("Failed to fetch") >= 0) {
77
76
  console.warn(`FaasReactClient: ${e.message} retry...`);
@@ -86,8 +85,9 @@ function FaasReactClient({
86
85
  }
87
86
  else
88
87
  setError(e);
88
+ setLoading(false);
89
89
  return Promise.reject(e);
90
- }).finally(() => setLoading(false));
90
+ });
91
91
  }
92
92
  if (options2 == null ? void 0 : options2.debounce) {
93
93
  const timeout = setTimeout(send, options2.debounce);
@@ -108,6 +108,7 @@ function FaasReactClient({
108
108
  if (params2)
109
109
  setParams(params2);
110
110
  setReloadTimes((prev) => prev + 1);
111
+ return promise;
111
112
  },
112
113
  [params]
113
114
  );
@@ -158,7 +159,14 @@ function FaasReactClient({
158
159
  return render(request);
159
160
  }
160
161
  return fallback || null;
161
- }, [loaded, request.action, request.params, request.data, request.error]);
162
+ }, [
163
+ loaded,
164
+ request.action,
165
+ request.params,
166
+ request.data,
167
+ request.error,
168
+ request.loading
169
+ ]);
162
170
  return child;
163
171
  }
164
172
  FaasDataWrapper2.whyDidYouRender = true;
@@ -232,63 +240,11 @@ var ErrorBoundary = class extends react.Component {
232
240
  }
233
241
  };
234
242
  ErrorBoundary.whyDidYouRender = true;
235
- function signal(initialValue, options = {}) {
236
- const state = signalsReact.signal(initialValue);
237
- if (options.debugName)
238
- signalsReact.effect(() => console.debug(options.debugName, state.value));
239
- return state;
240
- }
241
- function useSignalState(initialValue, options = {}) {
242
- const state = runtime.useSignal(initialValue);
243
- if (options.debugName) {
244
- runtime.useSignalEffect(() => console.log(options.debugName, state.value));
245
- }
246
- return [
247
- state.value,
248
- (changes) => {
249
- state.value = typeof changes === "function" ? changes(state.value) : changes;
250
- }
251
- ];
252
- }
253
243
 
254
- Object.defineProperty(exports, "batch", {
255
- enumerable: true,
256
- get: function () { return signalsReact.batch; }
257
- });
258
- Object.defineProperty(exports, "computed", {
259
- enumerable: true,
260
- get: function () { return signalsReact.computed; }
261
- });
262
- Object.defineProperty(exports, "effect", {
263
- enumerable: true,
264
- get: function () { return signalsReact.effect; }
265
- });
266
- Object.defineProperty(exports, "originSignal", {
267
- enumerable: true,
268
- get: function () { return signalsReact.signal; }
269
- });
270
- Object.defineProperty(exports, "originUseSignal", {
271
- enumerable: true,
272
- get: function () { return runtime.useSignal; }
273
- });
274
- Object.defineProperty(exports, "useComputed", {
275
- enumerable: true,
276
- get: function () { return runtime.useComputed; }
277
- });
278
- Object.defineProperty(exports, "useSignalEffect", {
279
- enumerable: true,
280
- get: function () { return runtime.useSignalEffect; }
281
- });
282
- Object.defineProperty(exports, "useSignals", {
283
- enumerable: true,
284
- get: function () { return runtime.useSignals; }
285
- });
286
244
  exports.ErrorBoundary = ErrorBoundary;
287
245
  exports.FaasDataWrapper = FaasDataWrapper;
288
246
  exports.FaasReactClient = FaasReactClient;
289
247
  exports.faas = faas;
290
248
  exports.getClient = getClient;
291
- exports.signal = signal;
292
249
  exports.useConstant = useConstant;
293
250
  exports.useFaas = useFaas;
294
- exports.useSignalState = useSignalState;
package/dist/index.mjs CHANGED
@@ -1,10 +1,6 @@
1
1
  import { useRef, useState, useEffect, Component, cloneElement, useCallback, useMemo } from 'react';
2
2
  import { FaasBrowserClient } from '@faasjs/browser';
3
3
  import { jsx, jsxs } from 'react/jsx-runtime';
4
- import { signal as signal$1, effect } from '@preact/signals-react';
5
- export { batch, computed, effect, signal as originSignal } from '@preact/signals-react';
6
- import { useSignal, useSignalEffect } from '@preact/signals-react/runtime';
7
- export { useSignal as originUseSignal, useComputed, useSignalEffect, useSignals } from '@preact/signals-react/runtime';
8
4
 
9
5
  // src/constant.ts
10
6
  function useConstant(fn) {
@@ -68,10 +64,11 @@ function FaasReactClient({
68
64
  { signal: controller.signal }
69
65
  );
70
66
  setPromise(request);
71
- request.then(
72
- (r) => (options2 == null ? void 0 : options2.setData) ? options2.setData(r.data) : setData(r.data)
73
- ).catch(async (e) => {
74
- if ((e == null ? void 0 : e.message) === "The user aborted a request." || (e == null ? void 0 : e.message) === "Aborted")
67
+ request.then((r) => {
68
+ (options2 == null ? void 0 : options2.setData) ? options2.setData(r.data) : setData(r.data);
69
+ setLoading(false);
70
+ }).catch(async (e) => {
71
+ if (typeof (e == null ? void 0 : e.message) === "string" && e.message.toLowerCase().indexOf("aborted") >= 0)
75
72
  return;
76
73
  if (!fails && typeof (e == null ? void 0 : e.message) === "string" && e.message.indexOf("Failed to fetch") >= 0) {
77
74
  console.warn(`FaasReactClient: ${e.message} retry...`);
@@ -86,8 +83,9 @@ function FaasReactClient({
86
83
  }
87
84
  else
88
85
  setError(e);
86
+ setLoading(false);
89
87
  return Promise.reject(e);
90
- }).finally(() => setLoading(false));
88
+ });
91
89
  }
92
90
  if (options2 == null ? void 0 : options2.debounce) {
93
91
  const timeout = setTimeout(send, options2.debounce);
@@ -108,6 +106,7 @@ function FaasReactClient({
108
106
  if (params2)
109
107
  setParams(params2);
110
108
  setReloadTimes((prev) => prev + 1);
109
+ return promise;
111
110
  },
112
111
  [params]
113
112
  );
@@ -158,7 +157,14 @@ function FaasReactClient({
158
157
  return render(request);
159
158
  }
160
159
  return fallback || null;
161
- }, [loaded, request.action, request.params, request.data, request.error]);
160
+ }, [
161
+ loaded,
162
+ request.action,
163
+ request.params,
164
+ request.data,
165
+ request.error,
166
+ request.loading
167
+ ]);
162
168
  return child;
163
169
  }
164
170
  FaasDataWrapper2.whyDidYouRender = true;
@@ -232,23 +238,5 @@ var ErrorBoundary = class extends Component {
232
238
  }
233
239
  };
234
240
  ErrorBoundary.whyDidYouRender = true;
235
- function signal(initialValue, options = {}) {
236
- const state = signal$1(initialValue);
237
- if (options.debugName)
238
- effect(() => console.debug(options.debugName, state.value));
239
- return state;
240
- }
241
- function useSignalState(initialValue, options = {}) {
242
- const state = useSignal(initialValue);
243
- if (options.debugName) {
244
- useSignalEffect(() => console.log(options.debugName, state.value));
245
- }
246
- return [
247
- state.value,
248
- (changes) => {
249
- state.value = typeof changes === "function" ? changes(state.value) : changes;
250
- }
251
- ];
252
- }
253
241
 
254
- export { ErrorBoundary, FaasDataWrapper, FaasReactClient, faas, getClient, signal, useConstant, useFaas, useSignalState };
242
+ export { ErrorBoundary, FaasDataWrapper, FaasReactClient, faas, getClient, useConstant, useFaas };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "1.7.1",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -22,17 +22,14 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@faasjs/browser": "1.7.1"
25
+ "@faasjs/browser": "2.0.0"
26
26
  },
27
27
  "peerDependencies": {
28
- "react": "*",
29
- "@preact/signals-react": "*"
28
+ "react": "*"
30
29
  },
31
30
  "devDependencies": {
32
31
  "@types/react": "*",
33
- "react": "*",
34
- "@preact/signals-react": "*",
35
- "@types/use-sync-external-store": "*"
32
+ "react": "*"
36
33
  },
37
34
  "engines": {
38
35
  "npm": ">=9.0.0",