import { Defined, StrictGuard } from '../utils/type-utils'; import { WireId } from '../utils/wire-id'; export interface StateWireGuard { ' state-wire': StrictGuard; } export interface StateWire extends StateWireGuard, WireId { /** * get current value * @returns current value */ getValue(): V; /** * set value * @param value - */ setValue(value: Defined): void; /** * subscribe for value change * @param callback - * @returns unsubscribe function */ subscribe(callback: (value: Defined) => void): () => void; } export function isWritableStateWire( wire: unknown, ): wire is StateWire { return !!( wire && (wire as any)[' state-wire'] && (wire as any)[' state-wire'][0] && (wire as any)[' state-wire'][1] ); } export function createStateWireGuard(): StateWireGuard { return { ' state-wire': [true /* read */, true /* write */] as any }; }