@unitedstatespowersquadrons/components 1.0.11 → 1.0.13
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
|
@@ -20,6 +20,26 @@ yarn
|
|
|
20
20
|
|
|
21
21
|
More detailed information is available for [Toasts](Toasts/Readme.md) usage.
|
|
22
22
|
|
|
23
|
+
## Reducer
|
|
24
|
+
|
|
25
|
+
To create a reducer, follow the following pattern, follow the pattern described
|
|
26
|
+
in [Reducer/Example](Reducer/Example).
|
|
27
|
+
|
|
28
|
+
### State without Dispatch
|
|
29
|
+
|
|
30
|
+
If you only need access to app state, but no dispatchable events, you can use
|
|
31
|
+
the simplified generator function:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { createContext } from "react";
|
|
35
|
+
import { buildUnreducableState } from "@unitedstatespowersquadrons/components";
|
|
36
|
+
import { AppState } from "./types";
|
|
37
|
+
|
|
38
|
+
const StateContext = createContext<AppState | null>(null);
|
|
39
|
+
|
|
40
|
+
export const { AppProvider, useAppState } = buildUnreducableState<AppState>(StateContext);
|
|
41
|
+
```
|
|
42
|
+
|
|
23
43
|
## Automated Testing
|
|
24
44
|
|
|
25
45
|
GitHub Actions will automatically run `eslint` and `tsc` on branch pushes.
|
|
@@ -4,7 +4,7 @@ import * as ReducerHandlers from "./reducerHandlers";
|
|
|
4
4
|
import { AppState, ServerResponse } from "./types";
|
|
5
5
|
import { buildReducer, RailsAppAction } from "../";
|
|
6
6
|
|
|
7
|
-
// If you want to add additional data to the server response, use type `RailsAppAction<
|
|
7
|
+
// If you want to add additional data to the server response, use type `RailsAppAction<ServerResponse>`.
|
|
8
8
|
// Otherwise, just use type `RailsAppAction`.
|
|
9
9
|
//
|
|
10
10
|
// If you need to access the available `type`s for your defined AppAction, use `AppActionType<AppAction>`
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { AppAction } from "./reducer";
|
|
2
|
-
import { ServerResponse } from "./types";
|
|
3
2
|
import { DispatchFunc, DispatchHandler } from "../types";
|
|
4
3
|
import wrapDispatch from "../wrapDispatch";
|
|
5
4
|
|
|
@@ -21,5 +20,5 @@ export const doSomething = (
|
|
|
21
20
|
|
|
22
21
|
// If you want to add additional data to the server response, pass in type `ServerResponse`.
|
|
23
22
|
// Otherwise, just leave the second type parameter unspecified.
|
|
24
|
-
return wrapDispatch
|
|
23
|
+
return wrapDispatch(dispatch, [actionType], handler);
|
|
25
24
|
};
|
package/Reducer/index.tsx
CHANGED
package/Toasts/toastHelpers.ts
CHANGED
|
@@ -13,13 +13,9 @@ export function createDismissToast(dispatch: DispatchFunc<ToastRemoveAppAction>)
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export function handleToasts<T extends AppStateWithToasts>(draft: Draft<T>, toasts: Toast[]) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
return handleToastsFunc;
|
|
16
|
+
if (toasts.length > 0) {
|
|
17
|
+
toasts.forEach(toast => addToast(draft, toast));
|
|
18
|
+
}
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
export function addToast<T extends AppStateWithToasts>(draft: Draft<T>, toastOptions: Toast) {
|