UNPKG

@connectv/core

Version:

agent-based reactive programming library for typescript/javascript

81 lines (80 loc) 2.56 kB
import { TrackCallback } from "../shared/types"; import { Source } from "../pin/source"; import { PinLike } from "../pin/pin-like"; import { Agent } from "./agent"; import { State, EqualityFunc } from "./state"; import { Signature } from "./signature"; export interface DeepAccessor { initial: any; set: PinLike; get: PinLike; bind(track: TrackCallback): void; } export declare type DeepChildFactory<T extends SimpleDeep> = (accessor: DeepAccessor, compare: EqualityFunc) => T; /** * * Represents non-keyed (simple) [deep states](https://connective.dev/docs/deep). * */ export declare class SimpleDeep extends Agent { /** * * can be used to force re-emission of state value. * */ readonly reemit: Source; /** * * the core state of this simple deep * */ readonly state: State; protected accessor: DeepAccessor; private downPropageteKey; private bound; constructor(state: State); constructor(accessor: DeepAccessor, compare?: EqualityFunc); constructor(stateOrAccessor: State | DeepAccessor, compare?: EqualityFunc | undefined); constructor(stateOrAccessor: State | DeepAccessor, compare?: EqualityFunc | undefined, signature?: Signature); sub(index: string | number): SimpleDeep; sub<T extends SimpleDeep>(index: string | number, factory: DeepChildFactory<T>): T; /** * * Allows reading or updating state's value directly. * */ get value(): any; set value(v: any); /** * * The equality function used by this deep state. Is used for change detection. * */ get compare(): EqualityFunc; /** * * Shortcut for `.in('value')`, on which the state receives new values. * [Read this](https://connective.dev/docs/state#signature) for more details. * */ get input(): PinLike; /** * * Shortcut for `.out('value')`, on which the state emits new values. * [Read this](https://connective.dev/docs/state#signature) for more details. * */ get output(): PinLike; /** * * Binds the underlying state. If this is a sub-state, it will also * allow up-propagation of state value, causing the parent state to pick up * changes made to the value of this sub-state. [Read this](https://connective.dev/docs/deep#two-way-data) * for more details and examples. * */ bind(): this; protected createOutput(_: string): PinLike; protected createEntries(): PinLike[]; protected createExits(): PinLike[]; }