@faasjs/react 0.0.4-beta.1 → 0.0.4-beta.10

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
@@ -201,7 +201,7 @@ ___
201
201
  | `debounce?` | `number` | send the last request after milliseconds |
202
202
  | `params?` | `FaasParams`<`PathOrData`\> | - |
203
203
  | `setData?` | `React.Dispatch`<`React.SetStateAction`<`FaasData`<`PathOrData`\>\>\> | - |
204
- | `skip?` | `boolean` | - |
204
+ | `skip?` | `boolean` \| (`params`: `FaasParams`<`PathOrData`\>) => `boolean` | if skip is true, will not send request |
205
205
 
206
206
  ## Functions
207
207
 
package/dist/index.d.mts CHANGED
@@ -58,7 +58,8 @@ type useFaasOptions<PathOrData extends FaasAction> = {
58
58
  params?: FaasParams<PathOrData>
59
59
  data?: FaasData<PathOrData>
60
60
  setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
61
- skip?: boolean
61
+ /** if skip is true, will not send request */
62
+ skip?: boolean | ((params: FaasParams<PathOrData>) => boolean)
62
63
  /** send the last request after milliseconds */
63
64
  debounce?: number
64
65
  }
package/dist/index.d.ts CHANGED
@@ -58,7 +58,8 @@ type useFaasOptions<PathOrData extends FaasAction> = {
58
58
  params?: FaasParams<PathOrData>
59
59
  data?: FaasData<PathOrData>
60
60
  setData?: React.Dispatch<React.SetStateAction<FaasData<PathOrData>>>
61
- skip?: boolean
61
+ /** if skip is true, will not send request */
62
+ skip?: boolean | ((params: FaasParams<PathOrData>) => boolean)
62
63
  /** send the last request after milliseconds */
63
64
  debounce?: number
64
65
  }
package/dist/index.js CHANGED
@@ -30,6 +30,16 @@ function FaasReactClient({
30
30
  const [params, setParams] = react.useState(defaultParams);
31
31
  const [reloadTimes, setReloadTimes] = react.useState(0);
32
32
  const [fails, setFails] = react.useState(0);
33
+ const [skip, setSkip] = react.useState(
34
+ typeof options2.skip === "function" ? options2.skip(defaultParams) : options2.skip
35
+ );
36
+ react.useEffect(() => {
37
+ setSkip(
38
+ typeof options2.skip === "function" ? options2.skip(params) : options2.skip
39
+ );
40
+ }, [
41
+ typeof options2.skip === "function" ? JSON.stringify(params) : options2.skip
42
+ ]);
33
43
  react.useEffect(
34
44
  function() {
35
45
  if (JSON.stringify(defaultParams) !== JSON.stringify(params)) {
@@ -40,7 +50,7 @@ function FaasReactClient({
40
50
  );
41
51
  react.useEffect(
42
52
  function() {
43
- if (!action || (options2 == null ? void 0 : options2.skip)) {
53
+ if (!action || skip) {
44
54
  setLoading(false);
45
55
  return;
46
56
  }
@@ -88,12 +98,7 @@ function FaasReactClient({
88
98
  setLoading(false);
89
99
  };
90
100
  },
91
- [
92
- action,
93
- JSON.stringify(options2.params || params),
94
- reloadTimes,
95
- options2.skip
96
- ]
101
+ [action, JSON.stringify(options2.params || params), reloadTimes, skip]
97
102
  );
98
103
  return {
99
104
  action,
package/dist/index.mjs CHANGED
@@ -28,6 +28,16 @@ function FaasReactClient({
28
28
  const [params, setParams] = useState(defaultParams);
29
29
  const [reloadTimes, setReloadTimes] = useState(0);
30
30
  const [fails, setFails] = useState(0);
31
+ const [skip, setSkip] = useState(
32
+ typeof options2.skip === "function" ? options2.skip(defaultParams) : options2.skip
33
+ );
34
+ useEffect(() => {
35
+ setSkip(
36
+ typeof options2.skip === "function" ? options2.skip(params) : options2.skip
37
+ );
38
+ }, [
39
+ typeof options2.skip === "function" ? JSON.stringify(params) : options2.skip
40
+ ]);
31
41
  useEffect(
32
42
  function() {
33
43
  if (JSON.stringify(defaultParams) !== JSON.stringify(params)) {
@@ -38,7 +48,7 @@ function FaasReactClient({
38
48
  );
39
49
  useEffect(
40
50
  function() {
41
- if (!action || (options2 == null ? void 0 : options2.skip)) {
51
+ if (!action || skip) {
42
52
  setLoading(false);
43
53
  return;
44
54
  }
@@ -86,12 +96,7 @@ function FaasReactClient({
86
96
  setLoading(false);
87
97
  };
88
98
  },
89
- [
90
- action,
91
- JSON.stringify(options2.params || params),
92
- reloadTimes,
93
- options2.skip
94
- ]
99
+ [action, JSON.stringify(options2.params || params), reloadTimes, skip]
95
100
  );
96
101
  return {
97
102
  action,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/react",
3
- "version": "0.0.4-beta.1",
3
+ "version": "0.0.4-beta.10",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -21,13 +21,14 @@
21
21
  "files": [
22
22
  "dist"
23
23
  ],
24
+ "dependencies": {
25
+ "@faasjs/browser": "0.0.4-beta.10"
26
+ },
24
27
  "peerDependencies": {
25
- "react": "*",
26
- "@faasjs/browser": "0.0.3-beta.109"
28
+ "react": "*"
27
29
  },
28
30
  "devDependencies": {
29
31
  "@types/react": "*",
30
- "@faasjs/browser": "0.0.4-beta.1",
31
32
  "react": "*"
32
33
  },
33
34
  "engines": {