@connectv/core
Version:
agent-based reactive programming library for typescript/javascript
72 lines (71 loc) • 1.89 kB
TypeScript
import { Subscription } from 'rxjs';
import { Tracker } from '../shared/tracker';
import { PinLike } from './pin-like';
export declare type PinMapFactory = (label: string) => PinLike;
export declare type PinMapSusbcriber = (label: string, pin: PinLike) => void;
/**
*
* Represents a map of labelled pins. The labelled pins are created
* first time they are requested, allowing for possibly huge
* maps without high memory cost.
*
*/
export declare class PinMap extends Tracker {
readonly factory: PinMapFactory;
private _pins;
private _subject;
/**
*
* @param factory will be used to create each new pin.
*
*/
constructor(factory?: PinMapFactory);
/**
*
* Fetches the pin with the given label, and create it if not
* created already.
*
* @param label
*
*/
get(label: string): PinLike;
/**
*
* Checks if a pin with given label is created, without
* creating the pin.
*
* @param label
*
*/
instantiated(label: string): boolean;
/**
*
* @returns an array of all created pins.
*
*/
get pins(): PinLike[];
/**
*
* @returns an entry list (pairs of `[string, Pin]`) of created pins.
*
*/
get entries(): [string, PinLike][];
/**
*
* Subscribes to the event of creation of a new pin. The subscriber function
* will also be invoked on all of the already created pairs.
*
* @param subscriber
* @returns a [`Subscription`](https://rxjs-dev.firebaseapp.com/guide/subscription) object
* that you can later unsubscribe from using `.unsubscribe()`
*
*/
subscribe(subscriber: PinMapSusbcriber): Subscription;
/**
*
* Clears all the created pins and remove references to them,
* also will remove all subscriptions.
*
*/
clear(): this;
}