UNPKG

haystack-react

Version:

Project Haystack utilities for building React applications

88 lines (87 loc) 2.52 kB
import { Client } from 'haystack-nclient'; import { HGrid, HRef, HList } from 'haystack-core'; /** * The grid result. */ export interface GridResult { /** * The grid result. */ grid: HGrid; /** * True if the grid's data is loading. */ isLoading: boolean; /** * The number of times a grid has been loaded. */ loads: number; /** * Truthy if the grid's data didn't load properly and threw an error. */ error?: Error; } /** * A grid result that can be refreshed. */ export interface GridRefreshResult extends GridResult { /** * Called to refresh any backing data queries. */ refresh: () => void; } /** * A hook that asynchronously resolves to a grid. * * @param options.getGrid An asynchronous method that resolves to a grid. * @param options.dependencies The dependencies that cause the grid to be refetched. * @returns A result that wraps the data. */ export declare function useGrid({ getGrid, dependencies, }: { getGrid: () => Promise<HGrid>; dependencies: ReadonlyArray<unknown>; }): GridResult; /** * The client context to be used. */ export declare const ClientContext: import("react").Context<Client>; /** * @returns The client to use for network communication. */ export declare function useClient(): Client; /** * A hook that restricts network communcations only to ops. */ export declare const OnlyOpsContext: import("react").Context<boolean>; /** * @returns true if only ops should be used for network communication. */ export declare function useOnlyOps(): boolean; /** * A hook that resolves a some ids into a grid. * * @param ids The ids to read from the server. * @returns A result that wraps the grid. */ export declare function useReadByIds(ids: string[] | HRef[] | HList<HRef>): GridRefreshResult; /** * A hook that resolves an id into a grid. * * @param id The id to read to read from the server. * @returns A result that wraps the grid. */ export declare function useReadById(id: string | HRef): GridRefreshResult; /** * A hook that resolves a haystack filter into a grid. * * @param filter The haystack filter to query from the server. * @returns A result that wraps the grid. */ export declare function useReadByFilter(filter: string): GridRefreshResult; /** * A hook that responses an expression into a grid. * * @param expr The expression to evalulate. * @returns The result that wraps the grid. */ export declare function useEval(expr: string): GridRefreshResult;