@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
72 lines (71 loc) • 2.92 kB
TypeScript
import { KeyFunc, ChangeMap as _ChangeMap } from "../util/keyed-array-diff";
import { PinLike } from "../pin/pin-like";
import { SimpleDeep, DeepAccessor, DeepChildFactory } from "./simple-deep";
import { State, EqualityFunc } from "./state";
export interface ChangeMap extends _ChangeMap {
/**
*
* Whether this is the first change map being calculated for a state or not.
*
*/
initial: boolean;
}
/**
*
* Represents a [keyed deep state](https://connective.dev/docs/deep#keyed-deep).
*
*/
export declare class KeyedDeep extends SimpleDeep {
readonly keyfunc: KeyFunc;
private _keyMap;
constructor(state: State, keyfunc: KeyFunc);
constructor(accessor: DeepAccessor, keyfunc: KeyFunc, compare?: EqualityFunc);
constructor(stateOrAccessor: State | DeepAccessor, keyfunc: KeyFunc, compare?: EqualityFunc | undefined);
key(key: string | number): SimpleDeep;
key<T extends SimpleDeep>(key: string | number, factory: DeepChildFactory<T>): T;
/**
*
* Returns a [pin](https://connective.dev/docs/pin) that reflects the reactive value of
* the index of entity identified by given key in the state's value. Entity `x` is said
* to be identified by key `k` if `state.keyfunc(x) === k`.
*
* @param key the key to identify target entity with
*
*/
index(key: string | number): PinLike;
/**
*
* Will bind the underlying state, and cause deep change-detection to happen upon
* changes of the state value. [Read this](https://connective.dev/docs/deep#change-detection)
* for more information on deep change-detection.
*
* If this is a sub-state, also enables 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-keyed) for more details
* and examples.
*
*/
bind(): this;
/**
*
* Keys that entities within the value of the state are identified with. Entity
* `x` is said to be indetified with key `k` if `state.keyfunc(x) === k`.
*
* **WARNING** the keys will not be calculcated unless deep change-detection is active.
* You can ensure deep change-detection is active by subscribing on `.changes` or
* calling `.bind()`. [Read this](https://connective.dev/docs/deep#change-detection)
* for more information on deep change-detection.
*
*/
get keys(): string[];
/**
*
* A [pin](https://connective.dev/docs/pin) that emits changes to this deep state's list value.
* These changes include entities being added to the list, removed from it or moved around in it.
* [Read this](https://connective.dev/docs/deep#change-detection) for more information on
* deep change-detection.
*
*/
get changes(): PinLike;
protected createOutput(label: string): PinLike;
}