@unitedstatespowersquadrons/components 1.2.6 → 1.2.7-pre.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.
- package/Reducer/buildReducer.tsx +11 -4
- package/package.json +3 -1
package/Reducer/buildReducer.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo } from "react";
|
|
2
2
|
import { Draft, produce } from "immer";
|
|
3
3
|
import { useImmerReducer } from "use-immer";
|
|
4
|
+
import ActionCable, { Cable } from "actioncable";
|
|
4
5
|
import { ReducerHandler } from "./types";
|
|
5
6
|
|
|
6
7
|
interface InitialAppProps<AppState> {
|
|
@@ -10,10 +11,14 @@ interface InitialAppProps<AppState> {
|
|
|
10
11
|
|
|
11
12
|
export default function buildReducer<AppState, AppAction>(
|
|
12
13
|
reducer: (draft: Draft<AppState>, action: AppAction) => void,
|
|
13
|
-
handlers: ReducerHandler<AppAction>[] = []
|
|
14
|
+
handlers: ReducerHandler<AppAction>[] = [],
|
|
15
|
+
actionCableUrl?: string
|
|
14
16
|
) {
|
|
15
17
|
const StateContext = createContext<AppState | null>(null);
|
|
16
18
|
const DispatchContext = createContext<React.Dispatch<AppAction> | null>(null);
|
|
19
|
+
const CableContext = createContext<Cable | null>(null);
|
|
20
|
+
|
|
21
|
+
const cable = actionCableUrl ? ActionCable.createConsumer(actionCableUrl) : null;
|
|
17
22
|
|
|
18
23
|
function AppProvider(props: InitialAppProps<AppState>) {
|
|
19
24
|
const [providerState, dispatch] = useImmerReducer(reducer, props.initialState, (state: AppState) => {
|
|
@@ -30,9 +35,11 @@ export default function buildReducer<AppState, AppAction>(
|
|
|
30
35
|
|
|
31
36
|
return (
|
|
32
37
|
<StateContext.Provider value={providerState}>
|
|
33
|
-
<
|
|
34
|
-
{
|
|
35
|
-
|
|
38
|
+
<CableContext.Provider value={cable}>
|
|
39
|
+
<DispatchContext.Provider value={wrappedDispatch}>
|
|
40
|
+
{props.children}
|
|
41
|
+
</DispatchContext.Provider>
|
|
42
|
+
</CableContext.Provider>
|
|
36
43
|
</StateContext.Provider>
|
|
37
44
|
);
|
|
38
45
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unitedstatespowersquadrons/components",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7-pre.1",
|
|
4
4
|
"description": "USPS shared React components library",
|
|
5
5
|
"main": "index.tsx",
|
|
6
6
|
"scripts": {
|
|
@@ -17,6 +17,8 @@
|
|
|
17
17
|
},
|
|
18
18
|
"homepage": "https://github.com/unitedstatespowersquadrons/components#readme",
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"@rails/actioncable": "^8.0.200",
|
|
21
|
+
"@types/actioncable": "^5.2.11",
|
|
20
22
|
"classnames": "^2.5.1",
|
|
21
23
|
"immer": "^10.1.1",
|
|
22
24
|
"react": "^19.1.0",
|