Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/SantaClaas/gigit. git client
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273/** * Calling the Rust side. * * Thin wrappers around `invoke`, so components never touch command names or * argument shapes directly. */
import { Channel, invoke } from "@tauri-apps/api/core";
import type { GraphEvent, OpenedRepository, RefEntry, RepositoryId, RepositorySummary,} from "./bindings";
export function openRepository(path: string): Promise<OpenedRepository> { return invoke("open_repository", { path });}
export function closeRepository(id: RepositoryId): Promise<boolean> { return invoke("close_repository", { id });}
export function repositorySummary(id: RepositoryId): Promise<RepositorySummary> { return invoke("repository_summary", { id });}
export function listReferences(id: RepositoryId): Promise<RefEntry[]> { return invoke("list_references", { id });}
/** A running graph stream. */export type GraphStream = { /** * Allow the backend to send `rows` more rows. Call this as the view * approaches the end of what it has. */ requestMore(rows: number): Promise<void>;};
/** * Start streaming the commit graph. * * Rows are pushed rather than requested one page at a time: `budget` rows are * on their way as soon as they exist, without a round trip, and nothing beyond * the budget is sent until {@link GraphStream.requestMore} raises it. That is * what keeps a million-commit repository from flooding the boundary while * still putting the first screen up immediately. * * Only one stream runs per repository — starting another replaces it and * restarts the walk from the newest commit. */export async function streamGraph( id: RepositoryId, budget: number, onEvent: (event: GraphEvent) => void,): Promise<GraphStream> { const channel = new Channel<GraphEvent>(); // Tauri's Channel is not an EventTarget — `onmessage` is the only way to // receive from it, so the usual advice to prefer addEventListener does not // apply here. // oxlint-disable-next-line unicorn/prefer-add-event-listener channel.onmessage = onEvent;
await invoke("stream_graph", { id, channel, budget });
return { requestMore: (rows: number) => invoke("request_more_rows", { id, rows }), };}