@fireflysemantics/slice
Version:

113 lines (112 loc) • 2.77 kB
TypeScript
import { Observable } from 'rxjs';
/**
* Initialize hte store with this.
*/
export interface ValueReset {
value: any;
reset?: any;
}
/**
* OStore Key Value Reset
*/
export interface ObsValueReset {
value: any;
reset?: any;
obs: Observable<any>;
}
export interface KeyObsValueReset {
[key: string]: ObsValueReset;
}
export interface OStoreStart {
[key: string]: ValueReset;
}
export declare class OStore<E extends KeyObsValueReset> {
/**
* Start keys and values
* passed in via constructor.
*/
S: E;
constructor(start: OStoreStart);
/**
* Reset the state of the OStore to the
* values or reset provided in the constructor
* {@link OStoreStart} instance.
*/
reset(): void;
/**
* Map of Key Value pair entries
* containing values store in this store.
*/
entries: Map<any, any>;
/**
* Map of replay subject id to `ReplaySubject` instance.
*/
private subjects;
/**
* Set create a key value pair entry and creates a
* corresponding replay subject instance that will
* be used to broadcast updates.
*
* @param key The key identifying the value
* @param value The value
*/
private post;
/**
* Update a value and notify subscribers.
*
* @param key
* @param value
*/
put(key: any, value: any): void;
/**
* Deletes both the value entry and the corresponding {@link ReplaySubject}.
* Will unsubscribe the {@link ReplaySubject} prior to deleting it,
* severing communication with corresponding {@link Observable}s.
*
* @param key
*/
delete(key: any): void;
/**
* Clear all entries.
*
* Note that
* this will call delete for on all
* keys defined which also also
* unsubscribes and deletes
* all the sbujects.
*/
clear(): void;
/**
* Observe changes to the values.
*
* @param key
* @return An {@link Observable} of the value
*/
observe(key: any): Observable<any> | undefined;
/**
* Check whether a value exists.
*
* @param key
* @return True if the entry exists ( Is not null or undefined ) and false otherwise.
*/
exists(key: any): boolean;
/**
* Retrieve a snapshot of the
* value.
*
* @param key
* @return A snapshot of the value corresponding to the key.
*/
snapshot(key: any): any;
/**
* Indicates whether the store is empty.
* @return true if the store is empty, false otherwise.
*/
isEmpty(): boolean;
/**
* Returns the number of key value pairs contained.
*
* @return the number of entries in the store.
*/
count(): number;
}