@adaskothebeast/react-redux-toolkit-hierarchical-date-hook 4.0.1 → 5.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/index.esm.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
function _extends() {
|
|
2
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
3
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
4
|
+
var t = arguments[e];
|
|
5
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
6
|
+
}
|
|
7
|
+
return n;
|
|
8
|
+
}, _extends.apply(null, arguments);
|
|
9
|
+
}
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* This custom hook transforms the string date fields based on matching regex to Date objects
|
|
@@ -21,16 +24,25 @@ import 'core-js/modules/web.structured-clone.js';
|
|
|
21
24
|
* import { hierarchicalConvertToJsJoda } from '@adaskothebeast/hierarchical-convert-to-js-joda';
|
|
22
25
|
* import { hierarchicalConvertToLuxon } from '@adaskothebeast/hierarchical-convert-to-luxon';
|
|
23
26
|
* import { hierarchicalConvertToMoment } from '@adaskothebeast/hierarchical-convert-to-moment';
|
|
27
|
+
* import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
|
|
28
|
+
*
|
|
29
|
+
* const MyComponent: React.FC = () => {
|
|
30
|
+
* const useQueryResult = useGetUserQuery(userId);
|
|
31
|
+
* const adjustedResult = useAdjustUseQueryHookResultWithHierarchicalDateConverter(
|
|
32
|
+
* useQueryResult,
|
|
33
|
+
* hierarchicalConvertToDate
|
|
34
|
+
* );
|
|
24
35
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
36
|
+
* if (adjustedResult.isLoading) {
|
|
37
|
+
* return <div>Loading...</div>;
|
|
38
|
+
* }
|
|
28
39
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
40
|
+
* if (adjustedResult.error) {
|
|
41
|
+
* return <div>Error: {adjustedResult.error}</div>;
|
|
42
|
+
* }
|
|
31
43
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
44
|
+
* return <div>User's name is {adjustedResult.data?.name}</div>;
|
|
45
|
+
* };
|
|
34
46
|
* ```
|
|
35
47
|
*
|
|
36
48
|
* @param useQueryResult The result of a Redux Toolkit query hook
|
|
@@ -38,18 +50,14 @@ import 'core-js/modules/web.structured-clone.js';
|
|
|
38
50
|
* @returns The original query result with its data field transformed, if it exists
|
|
39
51
|
*/
|
|
40
52
|
function useAdjustUseQueryHookResultWithHierarchicalDateConverter(useQueryResult, convertFunc) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (result.data) {
|
|
44
|
-
// Deep clone the data to avoid mutating the state directly
|
|
45
|
-
const clonedData = structuredClone(result.data);
|
|
53
|
+
if (useQueryResult.data) {
|
|
54
|
+
const clonedData = structuredClone(useQueryResult.data);
|
|
46
55
|
convertFunc(clonedData);
|
|
47
|
-
return
|
|
56
|
+
return _extends({}, useQueryResult, {
|
|
48
57
|
data: clonedData
|
|
49
|
-
});
|
|
58
|
+
});
|
|
50
59
|
}
|
|
51
|
-
|
|
52
|
-
return result;
|
|
60
|
+
return useQueryResult;
|
|
53
61
|
}
|
|
54
62
|
|
|
55
63
|
export { useAdjustUseQueryHookResultWithHierarchicalDateConverter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaskothebeast/react-redux-toolkit-hierarchical-date-hook",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Adam Pluciński <adaskothebeast@gmail.com> (https://github.com/adaskothebeast)",
|
|
6
6
|
"repository": {
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
},
|
|
13
13
|
"homepage": "https://github.com/AdaskoTheBeAsT/date-interceptors",
|
|
14
14
|
"peerDependencies": {
|
|
15
|
-
"@reduxjs/toolkit": "^2.2.5",
|
|
16
15
|
"jest-environment-jsdom": "*"
|
|
17
16
|
},
|
|
18
17
|
"sideEffects": false,
|
|
19
18
|
"module": "./index.esm.js",
|
|
20
19
|
"type": "module",
|
|
21
|
-
"main": "./index.esm.js"
|
|
20
|
+
"main": "./index.esm.js",
|
|
21
|
+
"types": "./index.esm.d.ts"
|
|
22
22
|
}
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface CustomQueryResult<ResultType> {
|
|
2
|
+
data?: ResultType;
|
|
3
|
+
error?: Error;
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
isFetching: boolean;
|
|
6
|
+
isSuccess: boolean;
|
|
7
|
+
isError: boolean;
|
|
8
|
+
refetch: () => void;
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
* This custom hook transforms the string date fields based on matching regex to Date objects
|
|
5
12
|
* of a Redux Toolkit query result using the HierarchicalConverter.
|
|
@@ -16,20 +23,30 @@ import { BaseQueryFn, QueryDefinition, TypedUseQueryStateResult } from '@reduxjs
|
|
|
16
23
|
* import { hierarchicalConvertToJsJoda } from '@adaskothebeast/hierarchical-convert-to-js-joda';
|
|
17
24
|
* import { hierarchicalConvertToLuxon } from '@adaskothebeast/hierarchical-convert-to-luxon';
|
|
18
25
|
* import { hierarchicalConvertToMoment } from '@adaskothebeast/hierarchical-convert-to-moment';
|
|
26
|
+
* import { hierarchicalConvertToDate } from '@adaskothebeast/hierarchical-convert-to-date';
|
|
19
27
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
28
|
+
* const MyComponent: React.FC = () => {
|
|
29
|
+
* const useQueryResult = useGetUserQuery(userId);
|
|
30
|
+
* const adjustedResult = useAdjustUseQueryHookResultWithHierarchicalDateConverter(
|
|
31
|
+
* useQueryResult,
|
|
32
|
+
* hierarchicalConvertToDate
|
|
33
|
+
* );
|
|
23
34
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
35
|
+
* if (adjustedResult.isLoading) {
|
|
36
|
+
* return <div>Loading...</div>;
|
|
37
|
+
* }
|
|
26
38
|
*
|
|
27
|
-
*
|
|
28
|
-
* }
|
|
39
|
+
* if (adjustedResult.error) {
|
|
40
|
+
* return <div>Error: {adjustedResult.error}</div>;
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* return <div>User's name is {adjustedResult.data?.name}</div>;
|
|
44
|
+
* };
|
|
29
45
|
* ```
|
|
30
46
|
*
|
|
31
47
|
* @param useQueryResult The result of a Redux Toolkit query hook
|
|
32
48
|
* @param convertFunc The function that performs the conversion in place
|
|
33
49
|
* @returns The original query result with its data field transformed, if it exists
|
|
34
50
|
*/
|
|
35
|
-
export declare function useAdjustUseQueryHookResultWithHierarchicalDateConverter<ResultType
|
|
51
|
+
export declare function useAdjustUseQueryHookResultWithHierarchicalDateConverter<ResultType>(useQueryResult: CustomQueryResult<ResultType>, convertFunc: (obj: object) => void): CustomQueryResult<ResultType>;
|
|
52
|
+
export {};
|