haystack-react
Version:
Project Haystack utilities for building React applications
47 lines (46 loc) • 1.8 kB
TypeScript
import { HDict, HGrid, HNum, HRef, HVal } from 'haystack-core';
/**
* A Haystack point record with a specific curVal type
*/
export interface Point<Value extends HVal> extends HDict {
/**
* Point record id
*/
id?: HRef;
/**
* Current value of the readTag
*/
curVal?: Value;
}
/**
* A hook that allows using a point from an haystack server as react state.
*
* Important: This hooks requires a ClientContext to work. @see https://github.com/j2inn/haystack-nclient
*
* @example <caption>Example of usage with a numeric point.</caption>
*
* const point= useReadByFilter('point and temp and zone and sp').grid[0] // One-shot reading the first point that matches the filter
* const [pointValue, setPointValue, updatedPoint] = useHaystackPoint<HNum>(point) // Using the point state
*
* @param originaryPoint point dict used to retrieve its id and initial value.
* @param pollRate poll rate for the value subscription. Expressed in seconds.
* @param writeOptions default options for the write callback.
* @returns Returns the point value, a function to update it and the point dict.
*/
export declare function useHaystackPoint<Value extends HVal>(originaryPoint: Optional<Point<Value>>, pollRate?: number, writeOptions?: HaystackPointWriteOptions): [
Optional<Value>,
PointWriteFunc<Value> | undefined,
Optional<Point<Value>>
];
type Optional<Value> = Value | undefined | null;
export type PointWriteFunc<Value extends HVal> = (val: Value, options?: HaystackPointWriteOptions) => Promise<HGrid<HDict>>;
/**
* Options for a PointWrite operation,
* See https://project-haystack.org/doc/docHaystack/Ops#pointWrite
*/
export interface HaystackPointWriteOptions {
level?: number;
who?: string;
duration?: number | HNum;
}
export {};