@unitedstatespowersquadrons/components 1.2.9-pre.1 → 1.2.9-pre.3
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { createContext, useContext, useEffect, useMemo
|
|
1
|
+
import React, { createContext, useContext, useEffect, useMemo } from "react";
|
|
2
2
|
import { Draft, produce } from "immer";
|
|
3
3
|
import { useImmerReducer } from "use-immer";
|
|
4
4
|
import { Cable, createConsumer } from "@rails/actioncable";
|
|
@@ -9,7 +9,7 @@ interface InitialAppProps<AppState> {
|
|
|
9
9
|
children: React.ReactNode;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default function
|
|
12
|
+
export default function buildReducer<AppState, AppAction>(
|
|
13
13
|
reducer: (draft: Draft<AppState>, action: AppAction) => void,
|
|
14
14
|
handlers: ReducerHandler<AppAction>[] = [],
|
|
15
15
|
actionCableUrl?: string
|
|
@@ -19,7 +19,7 @@ export default function useBuildReducer<AppState, AppAction>(
|
|
|
19
19
|
const CableContext = createContext<Cable | null>(null);
|
|
20
20
|
|
|
21
21
|
const cable = actionCableUrl ? createConsumer(actionCableUrl) : null;
|
|
22
|
-
|
|
22
|
+
let subscription: ChannelCallbacks;
|
|
23
23
|
|
|
24
24
|
function AppProvider(props: InitialAppProps<AppState>) {
|
|
25
25
|
const [providerState, dispatch] = useImmerReducer(reducer, props.initialState, (state: AppState) => {
|
|
@@ -67,14 +67,19 @@ export default function useBuildReducer<AppState, AppAction>(
|
|
|
67
67
|
useEffect(() => {
|
|
68
68
|
const { channel, dispatch, ...rest } = options;
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
subscription = appCable.subscriptions.create(
|
|
71
71
|
{ channel, ...rest } as ChannelSubscriptionOptions,
|
|
72
72
|
{
|
|
73
73
|
received: (data: object) => dispatch({ data, type: "receivedCable" }),
|
|
74
74
|
} as ChannelCallbacks
|
|
75
75
|
);
|
|
76
76
|
|
|
77
|
-
return
|
|
77
|
+
return(
|
|
78
|
+
() => {
|
|
79
|
+
console.log({ subscription: "stop" });
|
|
80
|
+
subscription.unsubscribe();
|
|
81
|
+
}
|
|
82
|
+
);
|
|
78
83
|
}, [appCable.subscriptions, options]);
|
|
79
84
|
|
|
80
85
|
return(cable!);
|
|
@@ -5,7 +5,7 @@ interface InitialAppProps<AppState> {
|
|
|
5
5
|
children: React.ReactNode;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
export default function
|
|
8
|
+
export default function buildUnreducibleState<AppState>() {
|
|
9
9
|
const StateContext = createContext<AppState | null>(null);
|
|
10
10
|
|
|
11
11
|
const AppProvider = (props: InitialAppProps<AppState>) => {
|
package/Reducer/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as wrapDispatch } from "./wrapDispatch";
|
|
2
|
-
export { default as buildReducer } from "./
|
|
3
|
-
export { default as buildUnreducibleState } from "./
|
|
2
|
+
export { default as buildReducer } from "./buildReducer";
|
|
3
|
+
export { default as buildUnreducibleState } from "./buildUnreducibleState";
|
|
4
4
|
export type * from "./types";
|