Skip to content

Commit 9cef378

Browse files
committed
refactor: update host comm hook naming
1 parent c1c976a commit 9cef378

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/ui/hooks/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { useRenderData } from "./useRenderData.js";
2-
export { useUIActions } from "./useUIActions.js";
2+
export { useHostCommunication } from "./useHostCommunication.js";
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ interface SendMessageOptions {
44
targetOrigin?: string;
55
}
66

7-
/** Return type for the useUIActions hook */
8-
interface UseUIActionsResult {
7+
/** Return type for the useHostCommunication hook */
8+
interface UseHostCommunicationResult {
99
/** Sends an intent message for the host to act on */
1010
intent: <T = unknown>(intent: string, params?: T) => void;
1111
/** Notifies the host of something that happened */
@@ -27,13 +27,13 @@ interface UseUIActionsResult {
2727
* @example
2828
* ```tsx
2929
* function MyComponent() {
30-
* const { intent, tool, link } = useUIActions();
30+
* const { intent, tool, link } = useHostCommunication();
3131
*
3232
* return <button onClick={() => intent("create-task", { title: "Buy groceries" })}>Create Task</button>;
3333
* }
3434
* ```
3535
*/
36-
export function useUIActions(defaultOptions?: SendMessageOptions): UseUIActionsResult {
36+
export function useHostCommunication(defaultOptions?: SendMessageOptions): UseHostCommunicationResult {
3737
const targetOrigin = defaultOptions?.targetOrigin ?? "*";
3838

3939
const intent = useCallback(
@@ -138,3 +138,4 @@ export function useUIActions(defaultOptions?: SendMessageOptions): UseUIActionsR
138138
[intent, notify, prompt, tool, link, reportSizeChange]
139139
);
140140
}
141+

src/ui/hooks/useRenderData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface UseRenderDataResult<T> {
3636
*
3737
* function MyComponent() {
3838
* const { data, isLoading, error, parentOrigin } = useRenderData<MyData>();
39-
* const { intent } = useUIActions({ targetOrigin: parentOrigin ?? undefined });
39+
* const { intent } = useHostCommunication({ targetOrigin: parentOrigin ?? undefined });
4040
* return <button onClick={() => intent("my-action")}>Click</button>;
4141
* }
4242
* ```

tests/unit/ui/useUIActions.test.ts renamed to tests/unit/ui/useHostCommunication.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { describe, it, expect, beforeEach, afterEach, vi, type Mock } from "vitest";
22
import { createElement, type FunctionComponent } from "react";
33
import { renderToString } from "react-dom/server";
4-
import { useUIActions } from "../../../src/ui/hooks/useUIActions.js";
4+
import { useHostCommunication } from "../../../src/ui/hooks/useHostCommunication.js";
55

6-
type UseUIActionsResult = ReturnType<typeof useUIActions>;
6+
type UseHostCommunicationResult = ReturnType<typeof useHostCommunication>;
77

88
interface HookOptions {
99
targetOrigin?: string;
@@ -13,11 +13,11 @@ interface HookOptions {
1313
* Simple hook testing utility that renders a component using the hook
1414
* and captures the result for assertions.
1515
*/
16-
function testHook(options?: HookOptions): UseUIActionsResult {
17-
let hookResult: UseUIActionsResult | undefined;
16+
function testHook(options?: HookOptions): UseHostCommunicationResult {
17+
let hookResult: UseHostCommunicationResult | undefined;
1818

1919
const TestComponent: FunctionComponent = () => {
20-
hookResult = useUIActions(options);
20+
hookResult = useHostCommunication(options);
2121
return null;
2222
};
2323

@@ -30,7 +30,7 @@ function testHook(options?: HookOptions): UseUIActionsResult {
3030
return hookResult;
3131
}
3232

33-
describe("useUIActions", () => {
33+
describe("useHostCommunication", () => {
3434
let postMessageMock: Mock;
3535
let originalWindow: typeof globalThis.window;
3636

@@ -233,3 +233,4 @@ describe("useUIActions", () => {
233233
expect(postMessageMock).toHaveBeenCalledWith(expect.any(Object), "*");
234234
});
235235
});
236+

0 commit comments

Comments
 (0)