@faasjs/react 2.2.0 → 2.3.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
@@ -7,6 +7,13 @@ React plugin for FaasJS.
7
7
 
8
8
  **If you use [SWR](https://swr.vercel.app) or [React Query / TanStack Query](https://tanstack.com/query), please use [`@faasjs/browser`](https://faasjs.com/doc/browser) directly.**
9
9
 
10
+ ## Features
11
+
12
+ - Support [FaasJS Request Specifications](https://faasjs.com/guide/request-spec.html).
13
+ - Support global and per-request configurations.
14
+ - Capiable with [why-did-you-render](https://github.com/welldone-software/why-did-you-render).
15
+ - Additional functions for React.
16
+
10
17
  ## Install
11
18
 
12
19
  ```sh
package/dist/index.d.mts CHANGED
@@ -2,8 +2,9 @@ import { FaasAction as FaasAction$1, FaasParams as FaasParams$1, FaasData as Faa
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';
5
- import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import * as react from 'react';
6
6
  import { ReactNode, ReactElement, Component } from 'react';
7
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
8
 
8
9
  /**
9
10
  * Returns a constant value that is created by the given function.
@@ -16,15 +17,14 @@ declare namespace useConstant {
16
17
  /**
17
18
  * Creates a splited context with the given default value.
18
19
  *
19
- * @template T - The type of the default value.
20
- * @param {T} defaultValue - The default value for the split context.
21
- * @returns {Object} - An object containing the Provider and use functions.
22
- *
23
20
  * @example
24
21
  * ```tsx
25
- * const { Provider, use } = createSplitedContext({
22
+ * const { Provider, use } = createSplitedContext<{
23
+ * value: number
24
+ * setValue: React.Dispatch<React.SetStateAction<number>>
25
+ * }>({
26
26
  * value: 0,
27
- * setValue: (_: any) => {},
27
+ * setValue: null,
28
28
  * })
29
29
  *
30
30
  * function ReaderComponent() {
@@ -43,38 +43,26 @@ declare namespace useConstant {
43
43
  * )
44
44
  * }
45
45
  *
46
- * const App = memo(() => {
47
- * return (
48
- * <>
49
- * <ReaderComponent />
50
- * <WriterComponent />
51
- * </>
52
- * )
53
- * })
54
- *
55
- * function Container() {
46
+ * function App() {
56
47
  * const [value, setValue] = useState(0)
57
48
  *
58
49
  * return (
59
50
  * <Provider value={{ value, setValue }}>
60
- * <App />
51
+ * <ReaderComponent />
52
+ * <WriterComponent />
61
53
  * </Provider>
62
54
  * )
63
55
  * }
64
56
  * ```
65
57
  */
66
- declare function createSplitedContext<T extends Record<string, any>>(defaultValue: T): {
67
- Provider: {
68
- (props: {
69
- value: T;
70
- children: React.ReactNode;
71
- }): react_jsx_runtime.JSX.Element;
72
- whyDidYouRender: boolean;
73
- };
74
- use: {
75
- (): Readonly<T>;
76
- whyDidYouRender: boolean;
77
- };
58
+ declare function createSplitedContext<T extends Record<string, any>>(defaultValue: {
59
+ [K in keyof T]: Partial<T[K]>;
60
+ }): {
61
+ Provider: (props: {
62
+ value?: Partial<T>;
63
+ children: React.ReactNode;
64
+ }) => react.ReactNode;
65
+ use: () => Readonly<T>;
78
66
  };
79
67
 
80
68
  type FaasReactClientInstance = {
package/dist/index.d.ts CHANGED
@@ -2,8 +2,9 @@ import { FaasAction as FaasAction$1, FaasParams as FaasParams$1, FaasData as Faa
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';
5
- import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import * as react from 'react';
6
6
  import { ReactNode, ReactElement, Component } from 'react';
7
+ import * as react_jsx_runtime from 'react/jsx-runtime';
7
8
 
8
9
  /**
9
10
  * Returns a constant value that is created by the given function.
@@ -16,15 +17,14 @@ declare namespace useConstant {
16
17
  /**
17
18
  * Creates a splited context with the given default value.
18
19
  *
19
- * @template T - The type of the default value.
20
- * @param {T} defaultValue - The default value for the split context.
21
- * @returns {Object} - An object containing the Provider and use functions.
22
- *
23
20
  * @example
24
21
  * ```tsx
25
- * const { Provider, use } = createSplitedContext({
22
+ * const { Provider, use } = createSplitedContext<{
23
+ * value: number
24
+ * setValue: React.Dispatch<React.SetStateAction<number>>
25
+ * }>({
26
26
  * value: 0,
27
- * setValue: (_: any) => {},
27
+ * setValue: null,
28
28
  * })
29
29
  *
30
30
  * function ReaderComponent() {
@@ -43,38 +43,26 @@ declare namespace useConstant {
43
43
  * )
44
44
  * }
45
45
  *
46
- * const App = memo(() => {
47
- * return (
48
- * <>
49
- * <ReaderComponent />
50
- * <WriterComponent />
51
- * </>
52
- * )
53
- * })
54
- *
55
- * function Container() {
46
+ * function App() {
56
47
  * const [value, setValue] = useState(0)
57
48
  *
58
49
  * return (
59
50
  * <Provider value={{ value, setValue }}>
60
- * <App />
51
+ * <ReaderComponent />
52
+ * <WriterComponent />
61
53
  * </Provider>
62
54
  * )
63
55
  * }
64
56
  * ```
65
57
  */
66
- declare function createSplitedContext<T extends Record<string, any>>(defaultValue: T): {
67
- Provider: {
68
- (props: {
69
- value: T;
70
- children: React.ReactNode;
71
- }): react_jsx_runtime.JSX.Element;
72
- whyDidYouRender: boolean;
73
- };
74
- use: {
75
- (): Readonly<T>;
76
- whyDidYouRender: boolean;
77
- };
58
+ declare function createSplitedContext<T extends Record<string, any>>(defaultValue: {
59
+ [K in keyof T]: Partial<T[K]>;
60
+ }): {
61
+ Provider: (props: {
62
+ value?: Partial<T>;
63
+ children: React.ReactNode;
64
+ }) => react.ReactNode;
65
+ use: () => Readonly<T>;
78
66
  };
79
67
 
80
68
  type FaasReactClientInstance = {
package/dist/index.js CHANGED
@@ -15,18 +15,19 @@ function useConstant(fn) {
15
15
  useConstant.whyDidYouRender = true;
16
16
  function createSplitedContext(defaultValue) {
17
17
  const contexts = {};
18
- for (const key of Object.keys(defaultValue))
18
+ const keys = Object.keys(defaultValue);
19
+ for (const key of keys)
19
20
  contexts[key] = react.createContext(defaultValue[key]);
20
21
  function Provider(props) {
22
+ var _a, _b;
21
23
  let children = props.children;
22
- for (const key of Object.keys(props.value)) {
24
+ for (const key of keys) {
23
25
  const Context = contexts[key];
24
- Context.Provider.whyDidYouRender = true;
25
- children = /* @__PURE__ */ jsxRuntime.jsx(Context.Provider, { value: props.value[key], children });
26
+ const value = (_b = (_a = props.value) == null ? void 0 : _a[key]) != null ? _b : defaultValue[key];
27
+ children = /* @__PURE__ */ jsxRuntime.jsx(Context.Provider, { value, children });
26
28
  }
27
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
29
+ return children;
28
30
  }
29
- Provider.whyDidYouRender = true;
30
31
  function use() {
31
32
  return useConstant(() => {
32
33
  const obj = /* @__PURE__ */ Object.create(null);
@@ -38,7 +39,6 @@ function createSplitedContext(defaultValue) {
38
39
  return Object.freeze(obj);
39
40
  });
40
41
  }
41
- use.whyDidYouRender = true;
42
42
  return {
43
43
  Provider,
44
44
  use
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { useRef, createContext, useState, useEffect, Component, cloneElement, useContext, useCallback, useMemo } from 'react';
2
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { FaasBrowserClient } from '@faasjs/browser';
4
4
 
5
5
  // src/constant.ts
@@ -13,18 +13,19 @@ function useConstant(fn) {
13
13
  useConstant.whyDidYouRender = true;
14
14
  function createSplitedContext(defaultValue) {
15
15
  const contexts = {};
16
- for (const key of Object.keys(defaultValue))
16
+ const keys = Object.keys(defaultValue);
17
+ for (const key of keys)
17
18
  contexts[key] = createContext(defaultValue[key]);
18
19
  function Provider(props) {
20
+ var _a, _b;
19
21
  let children = props.children;
20
- for (const key of Object.keys(props.value)) {
22
+ for (const key of keys) {
21
23
  const Context = contexts[key];
22
- Context.Provider.whyDidYouRender = true;
23
- children = /* @__PURE__ */ jsx(Context.Provider, { value: props.value[key], children });
24
+ const value = (_b = (_a = props.value) == null ? void 0 : _a[key]) != null ? _b : defaultValue[key];
25
+ children = /* @__PURE__ */ jsx(Context.Provider, { value, children });
24
26
  }
25
- return /* @__PURE__ */ jsx(Fragment, { children });
27
+ return children;
26
28
  }
27
- Provider.whyDidYouRender = true;
28
29
  function use() {
29
30
  return useConstant(() => {
30
31
  const obj = /* @__PURE__ */ Object.create(null);
@@ -36,7 +37,6 @@ function createSplitedContext(defaultValue) {
36
37
  return Object.freeze(obj);
37
38
  });
38
39
  }
39
- use.whyDidYouRender = true;
40
40
  return {
41
41
  Provider,
42
42
  use
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
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": "2.2.0"
25
+ "@faasjs/browser": "2.3.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": "*"