History

nicer ui

Rhys Sullivan committed 8 months ago

Commit ece99cf1 parent 8f20d5b14 files · +843 −160Browse files

Showing the changes to packages/react/src (1 of 14 files). Show all

Unified · Split

packages/react/src/index.ts+37−1
@@ -1,5 +1,5 @@
1import { Atom, Result } from "@effect-atom/atom";1import { Atom, Result } from "@effect-atom/atom";
2import { RegistryProvider, useAtomValue } from "@effect-atom/atom-react";2import { RegistryContext, RegistryProvider, useAtomValue } from "@effect-atom/atom-react";
3import type {3import type {
4 LocalInstallation,4 LocalInstallation,
5 Source,5 Source,
@@ -315,6 +315,42 @@ export const useSourceDiscovery = (input: { · 309 unmodified lines
315 return workspace.enabled ? results : pendingLoadable(workspace.workspace);315 return workspace.enabled ? results : pendingLoadable(workspace.workspace);
316};316};
317 317
318// ---------------------------------------------------------------------------
319// Prefetching
320// ---------------------------------------------------------------------------
321
322/**
323 * Returns a function that imperatively triggers a fetch for a tool detail.
324 * Because the atom family uses `Atom.keepAlive`, the fetched result persists
325 * in the registry. When the user later selects the tool, `useSourceToolDetail`
326 * gets an instant cache hit.
327 *
328 * Usage: call the returned function on pointer-enter with a short delay.
329 * It returns a cleanup function (unmounts the atom subscription).
330 */
331export const usePrefetchToolDetail = () => {
332 const registry = React.useContext(RegistryContext);
333 const workspace = useWorkspaceRequestContext();
334
335 return React.useCallback(
336 (sourceId: string, toolPath: string): (() => void) => {
337 if (!workspace.enabled) return () => {};
338 const requestedSourceId = sourceId as Source["id"];
339 const atom = sourceInspectionToolAtom(
340 encodeAtomKey([
341 workspace.enabled,
342 workspace.workspaceId,
343 workspace.accountId,
344 requestedSourceId,
345 toolPath,
346 ]),
347 );
348 // mount triggers the fetch; returns a dispose function
349 return registry.mount(atom);
350 },
351 [registry, workspace.enabled, workspace.workspaceId, workspace.accountId],
352 );
353};
318 354
319export type {355export type {
320 LocalInstallation,356 LocalInstallation,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t