@unitedstatespowersquadrons/components 1.2.9-pre.1 → 1.2.9-pre.2

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
1
  import { AppState } from "./types";
2
- import buildUnreducibleState from "../useBuildUnreducibleState";
2
+ import buildUnreducibleState from "../buildUnreducibleState";
3
3
 
4
4
  export const { AppProvider, useAppState } = buildUnreducibleState<AppState>();
@@ -1,4 +1,4 @@
1
- import React, { createContext, useContext, useEffect, useMemo, useRef } from "react";
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 useBuildReducer<AppState, AppAction>(
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
- const cableRef = useRef<ChannelCallbacks>(null);
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,14 @@ export default function useBuildReducer<AppState, AppAction>(
67
67
  useEffect(() => {
68
68
  const { channel, dispatch, ...rest } = options;
69
69
 
70
- cableRef.current = appCable.subscriptions.create(
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 () => cableRef.current!.unsubscribe();
77
+ return () => subscription.unsubscribe();
78
78
  }, [appCable.subscriptions, options]);
79
79
 
80
80
  return(cable!);
@@ -5,7 +5,7 @@ interface InitialAppProps<AppState> {
5
5
  children: React.ReactNode;
6
6
  }
7
7
 
8
- export default function useBuildUnreducibleState<AppState>() {
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 "./useBuildReducer";
3
- export { default as buildUnreducibleState } from "./useBuildUnreducibleState";
2
+ export { default as buildReducer } from "./buildReducer";
3
+ export { default as buildUnreducibleState } from "./buildUnreducibleState";
4
4
  export type * from "./types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.2.9-pre.1",
3
+ "version": "1.2.9-pre.2",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {