@towns-protocol/sdk
Version:
For more details, visit the following resources:
44 lines • 1.48 kB
TypeScript
import { Observable } from './observable';
/**
* Combines multiple observables into a single observable object.
*
* The Combine class creates a new observable that contains the current values
* of all input observables as properties. When any input observable changes,
* the combined observable will emit a new value with all current values.
*
* @example
* ```typescript
* const nameObs = new Observable('John')
* const ageObs = new Observable(25)
* const isActiveObs = new Observable(true)
*
* const combined = combine({
* name: nameObs,
* age: ageObs,
* isActive: isActiveObs,
* })
*
* // combined.value will be: { name: "John", age: 25, isActive: true }
*
* // Subscribe to changes in the combined observable
* combined.subscribe((newValue, prevValue) => {
* console.log('Combined value changed:', newValue)
* })
*
* // Changing any input observable will trigger the combined observable
* nameObs.setValue('Jane') // combined.value becomes { name: "Jane", age: 25, isActive: true }
* ```
*
*/
export declare const combine: <T extends Record<string, any>>(observables: { [K in keyof T]: Observable<T[K]>; }) => Combine<T>;
declare class Combine<T extends Record<string, any>> extends Observable<T> {
private observables;
private unsubscribers;
constructor(observables: {
[K in keyof T]: Observable<T[K]>;
});
private updateCombinedValue;
dispose(): void;
}
export {};
//# sourceMappingURL=combine.d.ts.map