@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
73 lines (72 loc) • 2.1 kB
TypeScript
import { Bindable } from '../shared/bindable';
import { PinLike } from '../pin/pin-like';
import { Agent } from './agent';
export declare type EqualityFunc = (a: any, b: any) => boolean;
/**
*
* Represents [state](https://connective.dev/docs/state) agents.
*
*/
export declare class State extends Agent implements Bindable {
/**
*
* The initial value of the agent
*
*/
readonly initial: any;
/**
*
* The equality check function
*
*/
readonly compare: EqualityFunc;
private _subject;
private _injector;
constructor();
constructor(initialOrCompare: any | EqualityFunc | undefined);
constructor(initial: any | undefined, compare: EqualityFunc | undefined);
/**
*
* 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;
/**
*
* Allows reading or updating `State`'s value directly. It will be equal
* to the latest value emitted by the `State`, and setting it, if the value
* has changed truly, will cause the `State` to emit the new value.
*
*/
get value(): any;
set value(v: any);
/**
*
* Causes the agent to start receiving values even
* without any subscribers.
*
*/
bind(): this;
/**
*
* @note `State`'s `.clear()` also causes a complete
* notification to be sent to observers.
*
*/
clear(): this;
protected createOutput(_: string): PinLike;
protected createEntries(): PinLike[];
protected createExits(): PinLike[];
}
export declare function state(): State;
export declare function state(initialOrCompare: any | EqualityFunc): State;
export declare function state(initial: any, compare: EqualityFunc): State;
export default state;