@unitedstatespowersquadrons/components 1.2.0 → 1.2.1
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.
|
@@ -8,7 +8,7 @@ export const doSomething = (
|
|
|
8
8
|
const actionType = "doSomething";
|
|
9
9
|
|
|
10
10
|
const handler: DispatchHandler<AppAction> = (action: AppAction) => {
|
|
11
|
-
if (action.type !== actionType) return
|
|
11
|
+
if (action.type !== actionType) return;
|
|
12
12
|
|
|
13
13
|
const { something } = action;
|
|
14
14
|
|
package/Reducer/types.ts
CHANGED
|
@@ -7,13 +7,13 @@ export interface RailsResponse {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export type DispatchFunc<T> = (action: T) => void;
|
|
10
|
-
|
|
11
|
-
body?: string;
|
|
10
|
+
interface DispatchData {
|
|
12
11
|
bodyJson?: object;
|
|
13
12
|
headers?: { [key: string]: string };
|
|
14
|
-
href
|
|
13
|
+
href: string;
|
|
15
14
|
method?: string;
|
|
16
|
-
}
|
|
15
|
+
}
|
|
16
|
+
export type DispatchHandler<T> = (action: T) => DispatchData | undefined;
|
|
17
17
|
|
|
18
18
|
export type ReducerHandler<AppAction> = (dispatch: DispatchFunc<AppAction>) => DispatchFunc<AppAction>;
|
|
19
19
|
|
package/Reducer/wrapDispatch.tsx
CHANGED
|
@@ -23,17 +23,20 @@ export default function wrapDispatch<
|
|
|
23
23
|
const updateDebounceTime = (("testEnv" in window) && window.testEnv) ? 50 : 250;
|
|
24
24
|
|
|
25
25
|
const updateHandler = async (action: A, signal: AbortSignal) => {
|
|
26
|
-
const
|
|
26
|
+
const handlerData = handler(action);
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
// If the handler returns nothing, this action shouldn't be processed
|
|
29
|
+
if (!handlerData) return;
|
|
29
30
|
|
|
30
|
-
const
|
|
31
|
+
const {
|
|
32
|
+
bodyJson = {},
|
|
33
|
+
headers = {},
|
|
34
|
+
href,
|
|
35
|
+
method = "POST",
|
|
36
|
+
} = handlerData;
|
|
31
37
|
|
|
32
38
|
try {
|
|
33
|
-
const res = await railsFetchJson<ServerResponse>(
|
|
34
|
-
href,
|
|
35
|
-
{ bodyJson, headers: requestHeaders, method: method || "POST", signal }
|
|
36
|
-
);
|
|
39
|
+
const res = await railsFetchJson<ServerResponse>(href, { bodyJson, headers, method, signal });
|
|
37
40
|
|
|
38
41
|
dispatch({ res, type: "saveComplete" } as A);
|
|
39
42
|
} catch(e) {
|