import { type ResourceReturn, createResource } from 'solid-js'; import type { Result } from '~bindings'; /** * A helper function which handles a Rust Result properly * @param cmd The command to call * @throws */ export default function useCommand( cmd: (...args: Args) => Promise>, ...args: Args ): ResourceReturn { return createResource(async () => await tryResult(cmd, ...args)); } export async function tryResult( cmd: (...args: Args) => Promise>, ...args: Args ): Promise { const value = await cmd(...args); if (value.status === 'ok') return value.data; throw value.error; }