@unitedstatespowersquadrons/components 1.2.0-pre.1 → 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
- export type DispatchHandler<T> = (action: T) => {
11
- body?: string;
10
+ interface DispatchData {
12
11
  bodyJson?: object;
13
12
  headers?: { [key: string]: string };
14
- href?: string;
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
 
@@ -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 { bodyJson, headers, href, method } = handler(action);
26
+ const handlerData = handler(action);
27
27
 
28
- if (!href || !bodyJson) return;
28
+ // If the handler returns nothing, this action shouldn't be processed
29
+ if (!handlerData) return;
29
30
 
30
- const requestHeaders = headers || {};
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) {
package/Toasts/Toasts.tsx CHANGED
@@ -55,4 +55,4 @@ const Toasts = (props: Props) => {
55
55
  );
56
56
  };
57
57
 
58
- export default Toasts;
58
+ export default Toasts;
package/eslint.config.mjs CHANGED
@@ -153,6 +153,7 @@ export default tseslint.config(
153
153
  "stylistic/semi": ["error", "always"],
154
154
  "stylistic/no-multiple-empty-lines": "error",
155
155
  "stylistic/jsx-sort-props": "error",
156
+ "stylistic/eol-last": "error",
156
157
  "stylistic/array-element-newline": [
157
158
  "error",
158
159
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.2.0-pre.1",
3
+ "version": "1.2.1",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {