@unitedstatespowersquadrons/components 1.2.8-pre.1 → 1.2.8

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,9 +1,10 @@
1
1
  import React from "react";
2
- import { useAppDispatch, useAppState } from "./reducer";
2
+ import { useAppCableSubscription, useAppDispatch, useAppState } from "./reducer";
3
3
 
4
4
  const SubComponent = () => {
5
5
  const { something } = useAppState();
6
6
  const dispatch = useAppDispatch();
7
+ const channel = useAppCableSubscription(dispatch, "ExampleChannel");
7
8
 
8
9
  const handleDoSomething = () => {
9
10
  const newSomething = "changed";
@@ -11,10 +12,15 @@ const SubComponent = () => {
11
12
  dispatch({ something: newSomething, type: "doSomething" });
12
13
  };
13
14
 
15
+ const sendUpstreamMessage = () => {
16
+ channel.send({ message: "upstream" });
17
+ };
18
+
14
19
  return(
15
- <div onClick={handleDoSomething}>
16
- {something}
17
- </div>
20
+ <>
21
+ <div onClick={handleDoSomething}>{something}</div>
22
+ <div onClick={sendUpstreamMessage}>Send Upstream</div>
23
+ </>
18
24
  );
19
25
  };
20
26
 
@@ -1,7 +1,7 @@
1
1
  import { Draft } from "immer";
2
2
  import * as ReducerHandlers from "./reducerHandlers";
3
3
  import { AppState, ServerResponse } from "./types";
4
- import { buildReducer, RailsAppAction } from "../";
4
+ import { buildReducer, CableAction, RailsAppAction } from "../";
5
5
 
6
6
  // If you want to add additional data to the server response, use type `RailsAppAction<ServerResponse>`.
7
7
  // Otherwise, just use type `RailsAppAction`.
@@ -9,6 +9,7 @@ import { buildReducer, RailsAppAction } from "../";
9
9
  // If you need to access the available `type`s for your defined AppAction, use `AppActionType<AppAction>`
10
10
  //
11
11
  export type AppAction =
12
+ | CableAction
12
13
  | RailsAppAction<ServerResponse>
13
14
  | { type: "doSomething"; something: string };
14
15
 
@@ -20,10 +21,16 @@ export const reducer = (draft: Draft<AppState>, action: AppAction): void => {
20
21
  draft.something = action.something;
21
22
 
22
23
  break;
24
+ case "receivedCable": break;
23
25
  case "saveComplete": break;
24
26
  case "saveFailed": break;
25
27
  default: return type satisfies never;
26
28
  }
27
29
  };
28
30
 
29
- export const { AppProvider, useAppDispatch, useAppState } = buildReducer(reducer, Object.values(ReducerHandlers));
31
+ export const {
32
+ AppProvider,
33
+ useAppCableSubscription,
34
+ useAppDispatch,
35
+ useAppState,
36
+ } = buildReducer(reducer, Object.values(ReducerHandlers));
package/Reducer/types.ts CHANGED
@@ -21,10 +21,7 @@ export interface GenericAppAction {
21
21
  type: string;
22
22
  }
23
23
 
24
- export interface CableAction {
25
- data: object;
26
- type: "receivedCable";
27
- }
24
+ export type CableAction = { data: object; type: "receivedCable" };
28
25
 
29
26
  export type RailsAppAction<R extends RailsResponse = RailsResponse> =
30
27
  | { type: "saveComplete"; res: R }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.2.8-pre.1",
3
+ "version": "1.2.8",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {