UNPKG

@activejs/core

Version:

Pragmatic, Reactive State Management for JavaScript Apps

95 lines (94 loc) 3.46 kB
import { Base } from './abstract-base'; import { Stream } from './stream'; import { ClusterConfig, ClusterItems, ClusterStreamObservableProducer, InstancesMapToValuesMap } from '../models'; /** * A Cluster is just a wrapper, a group, of two or more ActiveJS fundamental constructs, `Units`, `Systems`, `Actions`, or even `Clusters`. * * It creates a master `Observable` of the combined value of its members by merging all the provided Observable constructs. * Whenever any of these wrapped constructs emits a value, `Cluster` emits a new combined-value. * * See {@link https://docs.activejs.dev/fundamentals/cluster} for more details. * * @category 4. Utility */ export declare class Cluster<T extends ClusterItems = ClusterItems, K extends keyof T = keyof T, V = InstancesMapToValuesMap<T>> extends Base<V> { /** * Configured options. \ * Combination of global-options {@link GlobalUnitConfig} and the options passed on instantiation. */ readonly config: Readonly<ClusterConfig>; /** * @internal please do not use. */ private itemsKeys; /** * The items part of this cluster, stored as key-value pairs. */ readonly items: Readonly<T>; /** * @internal please do not use. */ private _itemsCount; /** * The count of items part of this cluster. */ get itemsCount(): number; /** * Combined value of the items part of this Cluster. * * @category Access Value */ value(): V; constructor(items: T, config?: ClusterConfig); /** * A helper method that creates a stream by subscribing to the Observable returned by the param `observableProducer` callback. * * Ideally the callback function creates an Observable by applying `Observable.pipe`. * * Just know that you should catch the error in a sub-pipe (ie: do not let it propagate to the main-pipe), otherwise * as usual the stream will stop working, and will not react on any further emissions. * * @param observableProducer A callback function that should return an Observable. * * @category Common */ createStream<R>(observableProducer: ClusterStreamObservableProducer<this, R>): Stream; /** * Select a child by providing its key. * * @param key The key of the child. * * @category Custom Cluster */ select<k extends K>(key: k): T[k]; /** * Performs the specified action for each child of the Cluster {@link items}. \ * It's a drop-in replacement for the `forEach` method. * * @param callbackFn A function that accepts up to three arguments. * forEvery calls the callbackFn function one time for each element in the list. * @param thisArg An object to which this keyword can refer in the callbackFn function. * If thisArg is omitted, undefined is used as this value. * * @category Custom Cluster */ forEvery(callbackFn: (item: T[K], key: K, index: number, entries: [K, T[K]][]) => void, thisArg?: any): void; /** Iterator */ [Symbol.iterator](): Iterator<[K, T[K]]>; /** * @internal please do not use. */ private extractItems; /** * @internal please do not use. */ private startListeningAndEmitting; /** * @internal please do not use. */ protected emit(value?: V): void; /** * @internal please do not use. */ private combinedEmittedValues; }