UNPKG

haystack-react

Version:

Project Haystack utilities for building React applications

32 lines (31 loc) 1.44 kB
import { HDict, HGrid, HRef, HVal } from 'haystack-core'; /** * A Haystack record. */ export interface Record extends HDict { /** * Id of the record */ id?: HRef; } /** * A hook to use a record tag from an haystack server as react state. * * IMPORTANT: writing is currently only supported with a FIN 5/SkySpark server. * * IMPORTANT: This hooks requires a ClientContext to work. @see https://github.com/j2inn/haystack-nclient * * @example <caption>Example of usage for a precision tag of type Number.</caption> * * const record = useReadByFilter('precision and point and temp and zone and sp').grid[0] // One-shot reading the first record that matches the filter * const [precision, setPrecision, updatedRecord] = useHaystackRecordTag<HNum>(record, "precision") // Using its tag state * * @param originalRecord record dict used to retrieve id and initial value. * @param tagName name of the tag. * @param pollRate poll rate for the value subscription. Expressed in seconds. * @returns Returns the point value, a function to update it and the point dict. */ export declare function useHaystackRecordTag<Value extends HVal>(originalRecord?: Record, tagName?: string, pollRate?: number): [Optional<Value>, RecordTagWriteFunc<Value> | undefined, Optional<Record>]; type Optional<Value> = Value | undefined | null; type RecordTagWriteFunc<Value extends HVal> = (val?: Value) => Promise<HGrid<HDict>>; export {};