@fireflysemantics/slice
Version:

98 lines (97 loc) • 3 kB
TypeScript
import { Predicate } from "./models";
import { AbstractStore } from "./AbstractStore";
import { EStore } from "./EStore";
export declare class Slice<E> extends AbstractStore<E> {
label: string;
predicate: Predicate<E>;
eStore: EStore<E>;
entries: Map<string, E>;
/**
* perform initial notification to all observers,
* such that operations like {@link combineLatest}{}
* will execute at least once.
*
* @param label The slice label
* @param predicate The slice predicate
* @param eStore The EStore instance containing the elements considered for slicing
*
* @example
* ```
* //Empty slice
* new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete);
*
* //Initialized slice
* let todos = [new Todo(false, "You complete me!"),
* new Todo(true, "You completed me!")];
* new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete, todos);
* ```
*/
constructor(label: string, predicate: Predicate<E>, eStore: EStore<E>);
/**
* Add the element if it satisfies the predicate
* and notify subscribers that an element was added.
*
* @param e The element to be considered for slicing
*/
post(e: E | E[]): void;
/**
* Add the elements if they satisfy the predicate
* and notify subscribers that elements were added.
*
* @param e The element to be considered for slicing
*/
postN(...e: E[]): void;
/**
* Add the elements if they satisfy the predicate
* and notify subscribers that elements were added.
*
* @param e The element to be considered for slicing
*/
postA(e: E[]): void;
/**
* Delete an element from the slice.
*
* @param e The element to be deleted if it satisfies the predicate
*/
delete(e: E | E[]): void;
/**
* @param e The elements to be deleted if it satisfies the predicate
*/
deleteN(...e: E[]): void;
/**
* @param e The elements to be deleted if they satisfy the predicate
*/
deleteA(e: E[]): void;
/**
* Update the slice when an Entity instance mutates.
*
* @param e The element to be added or deleted depending on predicate reevaluation
*/
put(e: E | E[]): void;
/**
* Update the slice with mutated Entity instances.
*
* @param e The elements to be deleted if it satisfies the predicate
*/
putN(...e: E[]): void;
/**
* @param e The elements to be put
*/
putA(e: E[]): void;
/**
* Resets the slice to empty.
*/
reset(): void;
/**
* Utility method that applies the predicate to an array
* of entities and return the ones that pass the test.
*
* Used to create an initial set of values
* that should be part of the `Slice`.
*
* @param p
* @param e
* @return The the array of entities that pass the predicate test.
*/
test(p: Predicate<E>, e: E[]): E[];
}