@hyper-fetch/react 8.1.1 → 8.2.2
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 +202 -52
- package/__tests__/features/helpers/use-request-events/use-request-events.base.spec.ts +1 -1
- package/__tests__/features/helpers/use-request-events/use-request-events.utils.spec.ts +1 -1
- package/__tests__/features/helpers/use-socket-state/use-socket-state.base.spec.ts +3 -3
- package/__tests__/features/helpers/use-tracked-state/use-tacked-state.actions.spec.ts +1 -1
- package/__tests__/features/helpers/use-tracked-state/use-tracked-state.base.spec.ts +55 -55
- package/__tests__/features/helpers/use-tracked-state/use-tracked-state.utils.spec.ts +8 -9
- package/__tests__/features/provider/provider.hydration.spec.tsx +3 -4
- package/__tests__/features/provider/use-config-provider.base.spec.tsx +1 -2
- package/__tests__/features/use-app-manager/use-app-manager.base.spec.ts +1 -1
- package/__tests__/features/use-cache/use-cache.base.spec.ts +6 -6
- package/__tests__/features/use-cache/use-cache.typescript.spec.ts +1 -2
- package/__tests__/features/use-emitter/use-emitter.base.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.base.spec.ts +13 -9
- package/__tests__/features/use-fetch/use-fetch.cancel.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.clear-state.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.concurrency.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.debounce.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.integration.spec.tsx +2 -2
- package/__tests__/features/use-fetch/use-fetch.keep-previous-data.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.methods.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.offline.spec.ts +1 -1
- package/__tests__/features/use-fetch/use-fetch.prefetch.spec.tsx +2 -2
- package/__tests__/features/use-fetch/use-fetch.refresh.spec.ts +3 -2
- package/__tests__/features/use-fetch/use-fetch.rerender.spec.tsx +3 -3
- package/__tests__/features/use-fetch/use-fetch.revalidate.spec.ts +47 -17
- package/__tests__/features/use-fetch/use-fetch.suspense.spec.tsx +4 -4
- package/__tests__/features/use-fetch/use-fetch.typescript.spec.ts +1 -2
- package/__tests__/features/use-fetch/use-fetch.utils.spec.ts +2 -2
- package/__tests__/features/use-fetch/use-fetch.window.spec.ts +1 -1
- package/__tests__/features/use-listener/use-listener.base.spec.ts +1 -1
- package/__tests__/features/use-queue/use-queue.actions.spec.ts +3 -3
- package/__tests__/features/use-queue/use-queue.base.spec.ts +13 -13
- package/__tests__/features/use-queue/use-queue.resolve.spec.ts +6 -6
- package/__tests__/features/use-stream/use-stream.base.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.base.spec.ts +2 -2
- package/__tests__/features/use-submit/use-submit.cancel.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.concurrency.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.debounce.spec.ts +15 -15
- package/__tests__/features/use-submit/use-submit.methods.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.optimistic.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.queue.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.retry.spec.ts +2 -2
- package/__tests__/features/use-submit/use-submit.revalidate.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.submit.spec.ts +1 -1
- package/__tests__/features/use-submit/use-submit.typescript.spec.ts +2 -3
- package/__tests__/shared/isolation.tests.ts +1 -1
- package/__tests__/shared/response.tests.ts +2 -2
- package/__tests__/tsconfig.json +11 -17
- package/__tests__/utils/cache.utils.ts +6 -6
- package/__tests__/utils/use-app-manager.utils.ts +0 -1
- package/__tests__/utils/use-cache.utils.ts +0 -1
- package/__tests__/utils/use-emitter.utils.ts +1 -2
- package/__tests__/utils/use-fetch.utils.ts +0 -1
- package/__tests__/utils/use-listener.utils.ts +1 -2
- package/__tests__/utils/use-queue.utils.ts +4 -5
- package/__tests__/utils/use-request-events.utils.ts +0 -1
- package/__tests__/utils/use-socket-state.utils.ts +1 -2
- package/__tests__/utils/use-submit.utils.ts +0 -1
- package/__tests__/utils/use-tracked-state.utils.ts +0 -1
- package/dist/helpers/use-request-events/use-request-events.hooks.d.ts.map +1 -1
- package/dist/helpers/use-request-events/use-request-events.types.d.ts.map +1 -1
- package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts.map +1 -1
- package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts.map +1 -1
- package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts.map +1 -1
- package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +1 -0
- package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts.map +1 -1
- package/dist/hooks/use-cache/use-cache.hooks.d.ts +1 -0
- package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -1
- package/dist/hooks/use-cache/use-cache.types.d.ts +2 -2
- package/dist/hooks/use-cache/use-cache.types.d.ts.map +1 -1
- package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +1 -0
- package/dist/hooks/use-emitter/use-emitter.hooks.d.ts.map +1 -1
- package/dist/hooks/use-emitter/use-emitter.types.d.ts +1 -0
- package/dist/hooks/use-emitter/use-emitter.types.d.ts.map +1 -1
- package/dist/hooks/use-fetch/use-fetch.constants.d.ts.map +1 -1
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +2 -1
- package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -1
- package/dist/hooks/use-fetch/use-fetch.types.d.ts.map +1 -1
- package/dist/hooks/use-listener/use-listener.hooks.d.ts +1 -0
- package/dist/hooks/use-listener/use-listener.hooks.d.ts.map +1 -1
- package/dist/hooks/use-listener/use-listener.types.d.ts +1 -0
- package/dist/hooks/use-listener/use-listener.types.d.ts.map +1 -1
- package/dist/hooks/use-queue/use-queue.constants.d.ts.map +1 -1
- package/dist/hooks/use-queue/use-queue.hooks.d.ts +2 -1
- package/dist/hooks/use-queue/use-queue.hooks.d.ts.map +1 -1
- package/dist/hooks/use-queue/use-queue.types.d.ts +6 -0
- package/dist/hooks/use-queue/use-queue.types.d.ts.map +1 -1
- package/dist/hooks/use-submit/use-submit.hooks.d.ts +2 -1
- package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -1
- package/dist/hooks/use-submit/use-submit.types.d.ts +1 -1
- package/dist/hooks/use-submit/use-submit.types.d.ts.map +1 -1
- package/dist/index.mjs +30 -22
- package/dist/index.mjs.map +1 -1
- package/dist/provider/provider.types.d.ts +4 -4
- package/dist/provider/provider.types.d.ts.map +1 -1
- package/dist/utils/bounce.utils.d.ts.map +1 -1
- package/dist/utils/deep-equal.utils.d.ts +2 -2
- package/dist/utils/deep-equal.utils.d.ts.map +1 -1
- package/dist/utils/tracked-proxy.utils.d.ts +1 -1
- package/dist/utils/tracked-proxy.utils.d.ts.map +1 -1
- package/package.json +8 -13
- package/src/helpers/use-request-events/use-request-events.hooks.ts +4 -5
- package/src/helpers/use-request-events/use-request-events.types.ts +0 -1
- package/src/helpers/use-socket-state/use-socket-state.hooks.ts +5 -6
- package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +11 -11
- package/src/helpers/use-tracked-state/use-tracked-state.types.ts +0 -1
- package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +12 -13
- package/src/hooks/use-app-manager/use-app-manager.hooks.ts +2 -2
- package/src/hooks/use-cache/use-cache.hooks.ts +4 -4
- package/src/hooks/use-cache/use-cache.types.ts +2 -3
- package/src/hooks/use-emitter/use-emitter.hooks.ts +4 -4
- package/src/hooks/use-emitter/use-emitter.types.ts +1 -0
- package/src/hooks/use-fetch/use-fetch.constants.ts +0 -1
- package/src/hooks/use-fetch/use-fetch.hooks.ts +14 -10
- package/src/hooks/use-fetch/use-fetch.types.ts +0 -1
- package/src/hooks/use-listener/use-listener.hooks.ts +3 -3
- package/src/hooks/use-listener/use-listener.types.ts +1 -0
- package/src/hooks/use-queue/use-queue.constants.ts +0 -1
- package/src/hooks/use-queue/use-queue.hooks.ts +3 -3
- package/src/hooks/use-queue/use-queue.types.ts +6 -0
- package/src/hooks/use-stream/use-stream.hooks.ts +4 -4
- package/src/hooks/use-submit/use-submit.hooks.ts +7 -7
- package/src/hooks/use-submit/use-submit.types.ts +1 -2
- package/src/provider/provider.types.ts +4 -5
- package/src/utils/bounce.utils.ts +1 -0
- package/src/utils/deep-equal.utils.ts +28 -12
- package/src/utils/tracked-proxy.utils.ts +1 -1
- package/tsconfig.json +11 -2
- package/vite.config.ts +14 -20
- package/.eslintrc.cjs +0 -12
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { useDidMount } from "@better-hooks/lifecycle";
|
|
2
|
+
import { useDebounce, useThrottle } from "@better-hooks/performance";
|
|
1
3
|
import type {
|
|
2
4
|
ExtractAdapterResolvedType,
|
|
3
5
|
RequestInstance,
|
|
@@ -9,19 +11,17 @@ import type {
|
|
|
9
11
|
ExtractAdapterType,
|
|
10
12
|
} from "@hyper-fetch/core";
|
|
11
13
|
import { sendRequest } from "@hyper-fetch/core";
|
|
12
|
-
import { useDidMount } from "@better-hooks/lifecycle";
|
|
13
|
-
import { useDebounce, useThrottle } from "@better-hooks/performance";
|
|
14
|
-
import { useMemo, useRef } from "react";
|
|
15
|
-
|
|
16
|
-
import type { UseSubmitOptionsType, UseSubmitReturnType } from "hooks/use-submit";
|
|
17
|
-
import { useSubmitDefaultOptions } from "hooks/use-submit";
|
|
18
14
|
import type { UseTrackedStateType } from "helpers";
|
|
19
15
|
import { useTrackedState, useRequestEvents } from "helpers";
|
|
16
|
+
import type { UseSubmitOptionsType, UseSubmitReturnType } from "hooks/use-submit";
|
|
17
|
+
import { useSubmitDefaultOptions } from "hooks/use-submit";
|
|
20
18
|
import { useProvider } from "provider";
|
|
19
|
+
import { useMemo, useRef } from "react";
|
|
21
20
|
import { createTrackedProxy, getBounceData } from "utils";
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
|
-
* This
|
|
23
|
+
* This hook aims to mutate data on the server. Unlike useFetch, it does not fire automatically -
|
|
24
|
+
* call the returned `submit` function to trigger the request (e.g., on button click).
|
|
25
25
|
* @param request
|
|
26
26
|
* @param options
|
|
27
27
|
* @returns
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type { ExtractAdapterResolvedType, NullableType, RequestInstance, RequestSendType } from "@hyper-fetch/core";
|
|
2
|
-
|
|
3
|
-
import type { isEqual } from "utils";
|
|
4
2
|
import type {
|
|
5
3
|
OnProgressCallbackType,
|
|
6
4
|
OnStartCallbackType,
|
|
@@ -10,6 +8,7 @@ import type {
|
|
|
10
8
|
UseTrackedStateType,
|
|
11
9
|
UseTrackedStateActions,
|
|
12
10
|
} from "helpers";
|
|
11
|
+
import type { isEqual } from "utils";
|
|
13
12
|
|
|
14
13
|
export type UseSubmitOptionsType<T extends RequestInstance> = {
|
|
15
14
|
/**
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { RequestInstance } from "@hyper-fetch/core";
|
|
2
|
-
import type React from "react";
|
|
3
|
-
|
|
4
|
-
import type { UseSubmitOptionsType } from "hooks/use-submit";
|
|
5
2
|
import type { UseCacheOptionsType } from "hooks/use-cache";
|
|
6
|
-
import type { UseQueueOptionsType } from "hooks/use-queue";
|
|
7
|
-
import type { UseListenerOptionsType } from "hooks/use-listener";
|
|
8
3
|
import type { UseEmitterOptionsType } from "hooks/use-emitter";
|
|
9
4
|
import type { UseFetchOptionsType } from "hooks/use-fetch";
|
|
5
|
+
import type { UseListenerOptionsType } from "hooks/use-listener";
|
|
6
|
+
import type { UseQueueOptionsType } from "hooks/use-queue";
|
|
7
|
+
import type { UseSubmitOptionsType } from "hooks/use-submit";
|
|
8
|
+
import type React from "react";
|
|
10
9
|
|
|
11
10
|
export type ProviderOptionsType = {
|
|
12
11
|
useFetchConfig?: Partial<UseFetchOptionsType<RequestInstance>>;
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
* @param value any object or primitive
|
|
4
4
|
* @returns true when value is empty
|
|
5
5
|
*/
|
|
6
|
-
export const isEmpty = (value
|
|
6
|
+
export const isEmpty = (value?: unknown): boolean => {
|
|
7
7
|
const valueType = Object.prototype.toString.call(value);
|
|
8
|
-
if (Array.isArray(value))
|
|
9
|
-
|
|
8
|
+
if (Array.isArray(value)) {
|
|
9
|
+
return value.length === 0;
|
|
10
|
+
}
|
|
11
|
+
if (typeof value === "object" && value !== null && valueType === "[object Object]") {
|
|
12
|
+
return Object.keys(value).length === 0;
|
|
13
|
+
}
|
|
10
14
|
return false;
|
|
11
15
|
};
|
|
12
16
|
|
|
@@ -16,9 +20,11 @@ export const isEmpty = (value: unknown): boolean => {
|
|
|
16
20
|
* @param secondValue unknown
|
|
17
21
|
* @returns true when elements are equal
|
|
18
22
|
*/
|
|
19
|
-
export const isEqual = (firstValue
|
|
23
|
+
export const isEqual = (firstValue?: unknown, secondValue?: unknown): boolean => {
|
|
20
24
|
// Nulls (objects), and other primitives
|
|
21
|
-
if (firstValue === secondValue)
|
|
25
|
+
if (firstValue === secondValue) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
22
28
|
|
|
23
29
|
try {
|
|
24
30
|
const firstValueType = Object.prototype.toString.call(firstValue);
|
|
@@ -31,24 +37,34 @@ export const isEqual = (firstValue: unknown, secondValue: unknown): boolean => {
|
|
|
31
37
|
const isTypeValue = (type: unknown) => firstValueType === type && secondValueType === type;
|
|
32
38
|
|
|
33
39
|
// Compared types are different
|
|
34
|
-
if (firstValueType !== secondValueType)
|
|
40
|
+
if (firstValueType !== secondValueType) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
35
43
|
|
|
36
44
|
// NaN
|
|
37
|
-
if (isType("number") && Number.isNaN(firstValue) && Number.isNaN(secondValue))
|
|
45
|
+
if (isType("number") && Number.isNaN(firstValue) && Number.isNaN(secondValue)) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
38
48
|
|
|
39
49
|
// Empty Array or Object
|
|
40
|
-
if (isEmpty(firstValue) && isEmpty(secondValue))
|
|
50
|
+
if (isEmpty(firstValue) && isEmpty(secondValue)) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
41
53
|
|
|
42
54
|
// Array
|
|
43
55
|
if (Array.isArray(firstValue) && Array.isArray(secondValue)) {
|
|
44
|
-
if (firstValue.length !== secondValue.length)
|
|
56
|
+
if (firstValue.length !== secondValue.length) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
45
59
|
|
|
46
60
|
return !firstValue.some((element, i) => !isEqual(element, secondValue[i]));
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
// Object
|
|
50
64
|
if (isType("object") && isTypeValue("[object Object]")) {
|
|
51
|
-
if (Object.keys(firstValue as object).length !== Object.keys(secondValue as object).length)
|
|
65
|
+
if (Object.keys(firstValue as object).length !== Object.keys(secondValue as object).length) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
52
68
|
|
|
53
69
|
return !Object.entries(firstValue as object).some(
|
|
54
70
|
([key, value]) => !isEqual(value, (secondValue as Record<string, unknown>)[key]),
|
|
@@ -62,8 +78,8 @@ export const isEqual = (firstValue: unknown, secondValue: unknown): boolean => {
|
|
|
62
78
|
|
|
63
79
|
// undefined, string, number, bool
|
|
64
80
|
return firstValue === secondValue;
|
|
65
|
-
} catch (
|
|
66
|
-
console.error(
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error(error);
|
|
67
83
|
return false;
|
|
68
84
|
}
|
|
69
85
|
};
|
package/tsconfig.json
CHANGED
|
@@ -2,8 +2,17 @@
|
|
|
2
2
|
"extends": "../../tsconfig.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"strict": true,
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"jsx": "react-jsx",
|
|
6
|
+
"paths": {
|
|
7
|
+
"helpers": ["./src/helpers"],
|
|
8
|
+
"helpers/*": ["./src/helpers/*"],
|
|
9
|
+
"hooks": ["./src/hooks"],
|
|
10
|
+
"hooks/*": ["./src/hooks/*"],
|
|
11
|
+
"provider": ["./src/provider"],
|
|
12
|
+
"provider/*": ["./src/provider/*"],
|
|
13
|
+
"utils": ["./src/utils"],
|
|
14
|
+
"utils/*": ["./src/utils/*"]
|
|
15
|
+
}
|
|
7
16
|
},
|
|
8
17
|
"exclude": ["node_modules", "dist", "vite.config.ts", "__tests__"]
|
|
9
18
|
}
|
package/vite.config.ts
CHANGED
|
@@ -1,45 +1,39 @@
|
|
|
1
1
|
/// <reference types="vitest/config" />
|
|
2
|
+
import path from "path";
|
|
2
3
|
import { defineConfig } from "vite";
|
|
3
4
|
import dts from "vite-plugin-dts";
|
|
4
5
|
import tsconfigPaths from "vite-tsconfig-paths";
|
|
5
|
-
|
|
6
|
-
import { getDtsCompilerOptionsForPackage } from "../../scripts/vite-dts-internal-paths";
|
|
6
|
+
|
|
7
7
|
import { getRollupExternalsFromPackageJson } from "../../scripts/vite-lib-externals-from-package";
|
|
8
8
|
|
|
9
9
|
export default defineConfig({
|
|
10
10
|
build: {
|
|
11
11
|
lib: {
|
|
12
12
|
entry: "src/index.ts",
|
|
13
|
-
formats: ["es"],
|
|
14
13
|
fileName: "index",
|
|
14
|
+
formats: ["es"],
|
|
15
15
|
},
|
|
16
|
-
sourcemap: true,
|
|
17
16
|
minify: false,
|
|
18
17
|
rollupOptions: {
|
|
19
18
|
external: getRollupExternalsFromPackageJson(__dirname),
|
|
20
19
|
},
|
|
20
|
+
sourcemap: true,
|
|
21
21
|
},
|
|
22
|
-
plugins: [
|
|
23
|
-
dts({
|
|
24
|
-
entryRoot: "src",
|
|
25
|
-
compilerOptions: getDtsCompilerOptionsForPackage(__dirname),
|
|
26
|
-
}),
|
|
27
|
-
tsconfigPaths(),
|
|
28
|
-
],
|
|
22
|
+
plugins: [tsconfigPaths(), dts({ entryRoot: "src" })],
|
|
29
23
|
test: {
|
|
30
|
-
globals: true,
|
|
31
|
-
environment: "jsdom",
|
|
32
|
-
setupFiles: ["./__tests__/vitest.setup.ts"],
|
|
33
|
-
include: ["__tests__/**/*.spec.{ts,tsx}", "src/**/*.spec.{ts,tsx}"],
|
|
34
|
-
coverage: {
|
|
35
|
-
provider: "v8",
|
|
36
|
-
include: ["src/**/*.{ts,tsx}"],
|
|
37
|
-
exclude: ["**/*.spec.*", "**/types.*", "**/constants.*", "**/index.ts"],
|
|
38
|
-
},
|
|
39
24
|
alias: {
|
|
40
25
|
"@hyper-fetch/core": path.resolve(__dirname, "../core/src/index.ts"),
|
|
41
26
|
"@hyper-fetch/sockets": path.resolve(__dirname, "../sockets/src/index.ts"),
|
|
42
27
|
"@hyper-fetch/testing": path.resolve(__dirname, "../testing/src/index.ts"),
|
|
43
28
|
},
|
|
29
|
+
coverage: {
|
|
30
|
+
exclude: ["**/*.spec.*", "**/types.*", "**/constants.*", "**/index.ts"],
|
|
31
|
+
include: ["src/**/*.{ts,tsx}"],
|
|
32
|
+
provider: "v8",
|
|
33
|
+
},
|
|
34
|
+
environment: "jsdom",
|
|
35
|
+
globals: true,
|
|
36
|
+
include: ["__tests__/**/*.spec.{ts,tsx}", "src/**/*.spec.{ts,tsx}"],
|
|
37
|
+
setupFiles: ["./__tests__/vitest.setup.ts"],
|
|
44
38
|
},
|
|
45
39
|
});
|
package/.eslintrc.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
extends: ["plugin:@nx/react", "../../.eslintrc.js"],
|
|
3
|
-
parserOptions: {
|
|
4
|
-
tsconfigRootDir: __dirname,
|
|
5
|
-
project: ["./tsconfig.json", "./__tests__/tsconfig.json"],
|
|
6
|
-
},
|
|
7
|
-
rules: {
|
|
8
|
-
"react/jsx-props-no-spreading": 0,
|
|
9
|
-
"react/require-default-props": 0,
|
|
10
|
-
},
|
|
11
|
-
ignorePatterns: ["dist/", "coverage/", "vite.config.ts", "/*.js"],
|
|
12
|
-
};
|