@faasjs/react 3.3.0 → 3.4.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/dist/index.d.mts CHANGED
@@ -2,7 +2,6 @@ import { FaasAction, FaasData, FaasParams } from '@faasjs/types';
2
2
  export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
3
3
  import { Response, BaseUrl, ResponseError, Options, FaasBrowserClient } from '@faasjs/browser';
4
4
  export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
5
- import * as react from 'react';
6
5
  import { ReactNode, ReactElement, Component, ComponentType, ComponentProps } from 'react';
7
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
7
 
@@ -62,7 +61,6 @@ declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T
62
61
  * Creates a splitting context with the given default value.
63
62
  *
64
63
  * @param defaultValue The default value of the splitting context.
65
- * @returns The provider component and the hook to use the splitting context.
66
64
  *
67
65
  * @example
68
66
  * ```tsx
@@ -104,11 +102,21 @@ declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T
104
102
  */
105
103
  declare function createSplittingContext<T extends Record<string, any>>(defaultValue: {
106
104
  [K in keyof T]: Partial<T[K]> | null;
107
- }): {
108
- Provider: (props: {
105
+ } | (keyof T)[]): {
106
+ /**
107
+ * The provider component of the splitting context.
108
+ * @see https://faasjs.com/doc/react/functions/createSplittingContext.html#provider
109
+ */
110
+ Provider(props: {
109
111
  value?: Partial<T>;
110
- children: React.ReactNode;
111
- }) => react.ReactNode;
112
+ children: ReactNode;
113
+ memo?: true | any[];
114
+ }): ReactNode;
115
+ /**
116
+ * The hook to use the splitting context.
117
+ *
118
+ * @see https://faasjs.com/doc/react/functions/createSplittingContext.html#use
119
+ */
112
120
  use: () => Readonly<T>;
113
121
  };
114
122
 
package/dist/index.d.ts CHANGED
@@ -2,7 +2,6 @@ import { FaasAction, FaasData, FaasParams } from '@faasjs/types';
2
2
  export { FaasAction, FaasData, FaasParams } from '@faasjs/types';
3
3
  import { Response, BaseUrl, ResponseError, Options, FaasBrowserClient } from '@faasjs/browser';
4
4
  export { Options, Response, ResponseError, ResponseHeaders } from '@faasjs/browser';
5
- import * as react from 'react';
6
5
  import { ReactNode, ReactElement, Component, ComponentType, ComponentProps } from 'react';
7
6
  import * as react_jsx_runtime from 'react/jsx-runtime';
8
7
 
@@ -62,7 +61,6 @@ declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T
62
61
  * Creates a splitting context with the given default value.
63
62
  *
64
63
  * @param defaultValue The default value of the splitting context.
65
- * @returns The provider component and the hook to use the splitting context.
66
64
  *
67
65
  * @example
68
66
  * ```tsx
@@ -104,11 +102,21 @@ declare function useEqualCallback<T extends (...args: any[]) => any>(callback: T
104
102
  */
105
103
  declare function createSplittingContext<T extends Record<string, any>>(defaultValue: {
106
104
  [K in keyof T]: Partial<T[K]> | null;
107
- }): {
108
- Provider: (props: {
105
+ } | (keyof T)[]): {
106
+ /**
107
+ * The provider component of the splitting context.
108
+ * @see https://faasjs.com/doc/react/functions/createSplittingContext.html#provider
109
+ */
110
+ Provider(props: {
109
111
  value?: Partial<T>;
110
- children: React.ReactNode;
111
- }) => react.ReactNode;
112
+ children: ReactNode;
113
+ memo?: true | any[];
114
+ }): ReactNode;
115
+ /**
116
+ * The hook to use the splitting context.
117
+ *
118
+ * @see https://faasjs.com/doc/react/functions/createSplittingContext.html#use
119
+ */
112
120
  use: () => Readonly<T>;
113
121
  };
114
122
 
package/dist/index.js CHANGED
@@ -77,14 +77,21 @@ function useEqualCallback(callback, dependencies) {
77
77
  );
78
78
  }
79
79
  function createSplittingContext(defaultValue) {
80
+ const keys = Array.isArray(defaultValue) ? defaultValue : Object.keys(defaultValue);
81
+ const defaultValues = Array.isArray(defaultValue) ? keys.reduce((prev, cur) => {
82
+ prev[cur] = null;
83
+ return prev;
84
+ }, {}) : defaultValue;
80
85
  const contexts = {};
81
- const keys = Object.keys(defaultValue);
82
- for (const key of keys) contexts[key] = react.createContext(defaultValue[key]);
86
+ for (const key of keys) contexts[key] = react.createContext(defaultValues[key]);
83
87
  function Provider(props) {
84
- let children = props.children;
88
+ let children = props.memo ? useEqualMemo(
89
+ () => props.children,
90
+ typeof props.memo === "boolean" ? [] : props.memo
91
+ ) : props.children;
85
92
  for (const key of keys) {
86
93
  const Context = contexts[key];
87
- const value = props.value?.[key] ?? defaultValue[key];
94
+ const value = props.value?.[key] ?? defaultValues[key];
88
95
  children = /* @__PURE__ */ jsxRuntime.jsx(Context.Provider, { value, children });
89
96
  }
90
97
  return children;
package/dist/index.mjs CHANGED
@@ -75,14 +75,21 @@ function useEqualCallback(callback, dependencies) {
75
75
  );
76
76
  }
77
77
  function createSplittingContext(defaultValue) {
78
+ const keys = Array.isArray(defaultValue) ? defaultValue : Object.keys(defaultValue);
79
+ const defaultValues = Array.isArray(defaultValue) ? keys.reduce((prev, cur) => {
80
+ prev[cur] = null;
81
+ return prev;
82
+ }, {}) : defaultValue;
78
83
  const contexts = {};
79
- const keys = Object.keys(defaultValue);
80
- for (const key of keys) contexts[key] = createContext(defaultValue[key]);
84
+ for (const key of keys) contexts[key] = createContext(defaultValues[key]);
81
85
  function Provider(props) {
82
- let children = props.children;
86
+ let children = props.memo ? useEqualMemo(
87
+ () => props.children,
88
+ typeof props.memo === "boolean" ? [] : props.memo
89
+ ) : props.children;
83
90
  for (const key of keys) {
84
91
  const Context = contexts[key];
85
- const value = props.value?.[key] ?? defaultValue[key];
92
+ const value = props.value?.[key] ?? defaultValues[key];
86
93
  children = /* @__PURE__ */ jsx(Context.Provider, { value, children });
87
94
  }
88
95
  return children;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -35,12 +35,12 @@
35
35
  ],
36
36
  "peerDependencies": {
37
37
  "react": "*",
38
- "@faasjs/browser": "3.3.0"
38
+ "@faasjs/browser": "3.4.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/react": "*",
42
42
  "react": "*",
43
- "@faasjs/browser": "3.3.0"
43
+ "@faasjs/browser": "3.4.0"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=22.0.0",