import * as plugins from './smartstate.plugins.js'; import { combineLatest, map } from 'rxjs'; import type { StatePart } from './smartstate.classes.statepart.js'; /** * creates a computed observable derived from multiple state parts. * the observable is lazy — it only subscribes to sources when subscribed to. */ export function computed( sources: StatePart[], computeFn: (...states: any[]) => TResult, ): plugins.smartrx.rxjs.Observable { return combineLatest(sources.map((sp) => sp.select())).pipe( map((states) => computeFn(...states)), ) as plugins.smartrx.rxjs.Observable; }