示例工程 17-react-state-and-data
17-react-state-and-data/app/shared/ipc.ts
export const CH = {
load: "data:load",
refresh: "data:refresh",
clearCache: "data:clear-cache",
update: "data:update",
windows: "data:windows",
openWindow: "data:open-window",
changed: "data:changed",
reset: "data:reset",
} as const;
export type Source = "cache" | "disk" | "network" | "broadcast";
export type Item = {
id: string;
title: string;
updatedAt: number;
};
export type LoadResult = {
items: Item[];
source: Source;
loadedAt: number;
};
export type Api = {
load(): Promise<LoadResult>;
refresh(): Promise<LoadResult>;
clearCache(): Promise<{ ok: boolean }>;
update(id: string, title: string): Promise<LoadResult>;
windows(): Promise<number>;
openWindow(): Promise<{ ok: boolean }>;
reset(): Promise<{ ok: boolean }>;
onChanged(cb: (result: LoadResult) => void): () => void;
};