mirror of
https://github.com/meshtastic/web.git
synced 2026-07-31 06:56:28 -04:00
refactor(sdk-react): rename useDevice → useMeshDevice
Prevents collision with packages/web's own useDevice() Zustand hook. All internal exports + tests updated; no behavior change. Callers migrating off @meshtastic/core should use useMeshDevice() from @meshtastic/sdk-react going forward.
This commit is contained in:
@@ -12,8 +12,8 @@ export { useMeshRegistry, useOptionalMeshRegistry } from "./src/adapters/useMesh
|
||||
export { useSignal } from "./src/adapters/useSignal.ts";
|
||||
export { useSignalValue } from "./src/adapters/useSignalValue.ts";
|
||||
|
||||
export { useDevice } from "./src/hooks/useDevice.ts";
|
||||
export type { UseDeviceResult } from "./src/hooks/useDevice.ts";
|
||||
export { useMeshDevice } from "./src/hooks/useMeshDevice.ts";
|
||||
export type { UseMeshDeviceResult } from "./src/hooks/useMeshDevice.ts";
|
||||
export { useConnection } from "./src/hooks/useConnection.ts";
|
||||
export type { UseConnectionResult } from "./src/hooks/useConnection.ts";
|
||||
export { useChat } from "./src/hooks/useChat.ts";
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { DeviceStatusEnum } from "@meshtastic/sdk";
|
||||
import { useClient } from "../adapters/useClient.ts";
|
||||
import { useSignal } from "../adapters/useSignal.ts";
|
||||
|
||||
export interface UseDeviceResult {
|
||||
export interface UseMeshDeviceResult {
|
||||
status: DeviceStatusEnum;
|
||||
isConfigured: boolean;
|
||||
myNodeNum: number | undefined;
|
||||
@@ -12,7 +12,13 @@ export interface UseDeviceResult {
|
||||
shutdown(seconds?: number): Promise<number>;
|
||||
}
|
||||
|
||||
export function useDevice(): UseDeviceResult {
|
||||
/**
|
||||
* Exposes the device slice of the current MeshClient: status, metadata, and
|
||||
* reboot/shutdown commands. Named `useMeshDevice` (not `useDevice`) so it does
|
||||
* not collide with consumer hooks of the same name (e.g. the legacy one in
|
||||
* `packages/web`).
|
||||
*/
|
||||
export function useMeshDevice(): UseMeshDeviceResult {
|
||||
const client = useClient();
|
||||
const status = useSignal(client.device.status);
|
||||
const isConfigured = useSignal(client.device.isConfigured);
|
||||
@@ -3,7 +3,7 @@ import { MeshClient } from "@meshtastic/sdk";
|
||||
import { createFakeTransport } from "@meshtastic/sdk/testing";
|
||||
import { ChannelNumber } from "@meshtastic/sdk";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { MeshProvider, useChat, useDevice } from "../mod.ts";
|
||||
import { MeshProvider, useChat, useMeshDevice } from "../mod.ts";
|
||||
|
||||
function setup() {
|
||||
const handle = createFakeTransport();
|
||||
@@ -15,9 +15,9 @@ function setup() {
|
||||
}
|
||||
|
||||
describe("sdk-react hooks", () => {
|
||||
it("useDevice re-renders on myNodeInfo", async () => {
|
||||
it("useMeshDevice re-renders on myNodeInfo", async () => {
|
||||
const { handle, wrapper } = setup();
|
||||
const { result } = renderHook(() => useDevice(), { wrapper });
|
||||
const { result } = renderHook(() => useMeshDevice(), { wrapper });
|
||||
expect(result.current.myNodeNum).toBeUndefined();
|
||||
|
||||
await act(async () => {
|
||||
|
||||
Reference in New Issue
Block a user