import { Subscribable, Observable, Subscription, Subject, BehaviorSubject, SchedulerLike, MonoTypeOperatorFunction, OperatorFunction, UnaryFunction } from 'rxjs'; type AccumulationFn = (st: T, sl: Partial) => T; interface Accumulator extends Subscribable { state: T; state$: Observable; signal$: Observable; subscribe: () => Subscription; nextSlice: (stateSlice: Partial) => void; nextSliceObservable: (state$: Observable>) => void; nextAccumulator: (fn: AccumulationFn) => void; } declare const defaultAccumulator: AccumulationFn; declare function createAccumulationObservable(stateObservables?: Subject>>, stateSlices?: Subject>, accumulatorObservable?: BehaviorSubject, scheduler?: SchedulerLike | null): Accumulator; /** * @description * The function which is used by `KeyCompareMap` to determine if changes are distinct or not. * Should return true if values are equal. * * @param {T} oldVal * @param {T} newVal * * @return boolean * * @docsPage interfaces * @docsCategory operators */ type CompareFn = (oldVal: T, newVal: T) => boolean; /** * @description * The `KeyCompareMap` is used to configure custom comparison for defined keys. * * @example * const keyCompareMap = { * myKey: (o, n) => customCompare(o, n) * }; * const o$ = of({ * myKey: 5, * myOtherKey: 'bar' * }).pipe(distinctUntilSomeChanged(['myKey', 'myOtherKey'], keyCompareMap)); * * //or * * const o$ = of({ * myKey: 5, * myOtherKey: 'bar' * }).pipe(selectSlice(['myKey', 'myOtherKey'], keyCompareMap)); * * @docsPage interfaces * @docsCategory operators */ type KeyCompareMap = { [K in keyof Partial]: CompareFn; }; type NonUndefined = T extends undefined ? never : T; type PickSlice = Pick; /** * @description * * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from * the previous item. Comparison will be done for each set key in the `keys` array. * * You can fine grain your distinct checks by providing a `KeyCompareMap` with those keys you want to compute * explicitly different * * The name `distinctUntilSomeChanged` was picked since it internally iterates over the `keys` and utilizes the * [some](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/some) method in order to * compute if values are distinct or not. * * @example * * import { of } from 'rxjs'; * import { distinctUntilSomeChanged } from 'rx-angular/state'; * * interface Person { * age: number; * name: string; * } * * of( * { age: 4, name: 'Hans'}, * { age: 7, name: 'Sophie'}, * { age: 5, name: 'Han Solo'}, * { age: 5, name: 'HanSophie'}, * ).pipe( * distinctUntilSomeChanged(['age', 'name']), * ) * .subscribe(x => console.log(x)); * * // displays: * // { age: 4, name: 'Hans'} * // { age: 7, name: 'Sophie'} * // { age: 5, name: 'Han Solo'} * // { age: 5, name: 'HanSophie'} * * @example * // An example with `KeyCompareMap` * import { of } from 'rxjs'; * import { distinctUntilSomeChanged } from 'rxjs/operators'; * * interface Person { * age: number; * name: string; * } * const customComparison: KeyCompareMap = { * name: (oldName, newName) => oldName.substring(0, 2) === newName.substring(0, 2) * }; * * of( * { age: 4, name: 'Hans'}, * { age: 7, name: 'Sophie'}, * { age: 5, name: 'Han Solo'}, * { age: 5, name: 'HanSophie'}, * ).pipe( * distinctUntilSomeChanged(['age', 'name'], customComparison), * ) * .subscribe(x => console.log(x)); * * // displays: * // { age: 4, name: 'Hans' } * // { age: 7, name: 'Sophie' } * // { age: 5, name: 'Han Solo' } * * @param {K[]} keys String key for object property lookup on each item. * @param {KeyCompareMap} [keyCompareMap] Optional KeyCompareMap to explicitly define comparisons for some of the keys * @docsPage distinctUntilSomeChanged * @docsCategory operators */ declare function distinctUntilSomeChanged(keys: K[], keyCompareMap?: KeyCompareMap): MonoTypeOperatorFunction; /** * @description * Returns the state as shared, replayed and distinct `Observable`. This way you don't have to think about late * subscribers, multiple subscribers or multiple emissions of the same value. * * @example * const state$ = state.pipe(select()); * state$.subscribe(state => doStuff(state)); * * @returns Observable */ declare function select(): MonoTypeOperatorFunction; /** * @description * Returns the state as cached and distinct `Observable`. Accepts arbitrary * [rxjs operators](https://rxjs-dev.firebaseapp.com/guide/operators) to enrich the selection with reactive composition. * * @example * const profilePicture$ = state.pipe( * select( * map(state => state.profilePicture), * switchMap(profilePicture => mapImageAsync(profilePicture)) * ) * ); * @param { OperatorFunction } op * @returns Observable * * @docsPage select * @docsCategory operators */ declare function select(op: OperatorFunction): OperatorFunction; /** * @internal */ declare function select(op1: OperatorFunction, op2: OperatorFunction): OperatorFunction; /** * @internal */ declare function select(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction): OperatorFunction; /** * @internal */ declare function select(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction): OperatorFunction; /** * @internal */ declare function select(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction): OperatorFunction; /** * @description * Transform a slice of the state by providing keys and map function. * Returns result of applying function to state slice as cached and distinct `Observable`. * * @example * // Project state slice * const text$ = state$.pipe( * select( * ['query', 'results'], * ({ query, results }) => `${results.length} results found for "${query}"` * ) * ); * * @return Observable */ declare function select(keys: K[], fn?: (slice: PickSlice) => R, keyCompareMap?: KeyCompareMap>): OperatorFunction; /** * @description * Transform a single property of the state by providing a key and map function. * Returns result of applying function to state property as cached and distinct `Observable`. * * @example * // Project state based on single property * const foo$ = state$.pipe(select('bar', bar => `bar equals ${bar}`)); * * @return Observable */ declare function select(k: K, fn: (val: T[K]) => R): OperatorFunction; /** * @description * Access a single property of the state by providing keys. * Returns a single property of the state as cached and distinct `Observable`. * * @example * // Access a single property * const bar$ = state$.pipe(select('bar')); * * // Access a nested property * const foo$ = state$.pipe(select('bar', 'foo')); * * @return Observable */ declare function select(k1: K1): OperatorFunction; /** * @internal */ declare function select(k1: K1, k2: K2): OperatorFunction; /** * @internal */ declare function select(k1: K1, k2: K2, k3: K3): OperatorFunction; /** * @internal */ declare function select(k1: K1, k2: K2, k3: K3, k4: K4): OperatorFunction; /** * @internal */ declare function select(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5): OperatorFunction; /** * @internal */ declare function select(k1: K1, k2: K2, k3: K3, k4: K4, k5: K5, k6: K6): OperatorFunction; /** * @description * * Returns an Observable that emits only the provided `keys` emitted by the source Observable. Each key will get * filtered to only emit _defined_ values as well as checked for distinct emissions. * Comparison will be done for each set key in the `keys` array. * * `selectSlice` will only emit _valid_ selections. A selection is _valid_ if every * selected key exists and is defined in the source Observable. This ensures that the `selectSlice` * operator will always return a complete slice with all values defined. * * You can fine grain your distinct checks by providing a `KeyCompareMap` with those keys you want to compute * explicitly different * * @example * * // An example with a custom comparison applied to each key * import { of } from 'rxjs'; * import { selectSlice } from 'rx-angular/state'; * * * const state$: Observable = of( * { title: 'myTitle', panelOpen: true}, * { title: 'myTitle2', panelOpen: true}, * { title: 'newTitle', panelOpen: true}, * { title: 'newTitle', panelOpen: false} * ) * .pipe( * selectSlice(['title', 'panelOpen']), * ) * .subscribe(x => console.log(x)); * * // displays: * // { title: 'myTitle', panelOpen: true }, * // { title: 'myTitle2', panelOpen: true }, * // { title: 'newTitle', panelOpen: true }, * // { title: 'newTitle', panelOpen: false } * * @example * * import { of, Observable } from 'rxjs'; * import { tap } from 'rxjs/operators'; * import { selectSlice } from 'rx-angular/state'; * * interface MyState { * title: string; * items: string[]; * panelOpen: boolean; * } * // Select items and title. * // apply custom compare logic for the items array * const customComparison: KeyCompareMap = { * items: (oldItems, newItems) => compareItems(oldItems, newItems) * }; * const state$: Observable = of( * { title: 'myTitle', items: ['foo', 'bar'], panelOpen: true }, * { title: 'myTitle', items: ['foo', 'bar'], panelOpen: false }, * { title: 'nextTitle', items: ['foo', 'baR'], panelOpen: true }, * { title: 'nextTitle', items: ['fooRz', 'boo'], panelOpen: false }, * ); * const slice$ = state$.pipe(selectSlice(['title', 'items'], customComparison), tap(console.log)).subscribe(); * * // displays: * // { title: 'myTitle', items: ['foo', 'bar'] } * // { title: 'nextTitle', items: ['foo', 'baR'] } * // { title: 'nextTitle', items: ['fooRz', 'boo'] } * * @param {(K)[]} keys - the array of keys which should be selected * @param {KeyCompareMap<{ [P in K]: T[P] }>} [keyCompareMap] Optional KeyCompareMap to provide custom compare logic * for some the keys * @docsPage selectSlice * @docsCategory operators */ declare function selectSlice(keys: K[], keyCompareMap?: KeyCompareMap<{ [P in K]: T[P]; }>): OperatorFunction>; /** * @description * * As the name `stateful` implies this operator is useful when you process an Observable which maintains state. * * Maintaining state as an `Observable` source comes with a handful of repetitive as well as use case specific tasks. * * It acts like the Observables `pipe` method. * It accepts RxJS operators and composes them like `Observable#pipe` and the standalone `pipe` method. * * Furthermore, it takes care of the above mentioned repetitive tasks as listed below. * * You will always (aka repetitive) want to ensure that: * - only distinct state changes are emitted * - only defined values are emitted (filter out undefined, which ensures lazy state) * - share and replay custom operations for multiple subscribers (saves performance) * * You will sometimes (aka situational) need: * - a subset of the state (derivations) * - compose the state with other Observables or change the Observables behaviour * * * @example * import { Observable } from 'rxjs'; * import { map } from 'rxjs/operators'; * import { stateful } from 'rx-angular/state'; * * const state$: Observable<{ name: string; items: string[] }>; * const derivation$ = state$.pipe( * stateful( * map(state => state.list.length), * filter(length => length > 3) * ) * ); * * @return OperatorFunction> * * @docsPage stateful * @docsCategory operators */ declare function stateful(): OperatorFunction>; /** * @internal */ declare function stateful(op: OperatorFunction): OperatorFunction>; /** * @internal */ declare function stateful(op1: OperatorFunction, op2: OperatorFunction): OperatorFunction>; /** * @internal */ declare function stateful(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction): OperatorFunction>; /** * @internal */ declare function stateful(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction): OperatorFunction>; /** * @internal */ declare function stateful(op1: OperatorFunction, op2: OperatorFunction, op3: OperatorFunction, op4: OperatorFunction, op5: OperatorFunction): OperatorFunction>; declare function createSideEffectObservable(stateObservables?: Subject>, scheduler?: SchedulerLike | null): { effects$: Observable; nextEffectObservable: (effect$: Observable) => void; subscribe: () => Subscription; } & Subscribable; declare function isOperateFnArrayGuard(op: any[]): op is OperatorFunction[]; declare function isStringArrayGuard(op: any[]): op is string[]; declare function isKeyOf(k: unknown): k is keyof O; declare function isObjectGuard(obj: unknown): obj is object; declare function isDefined(val: unknown): val is NonNullable; declare function isStringAndFunctionTupleGuard(op: unknown[]): op is [string, (val: any) => R]; declare function isStringArrayFunctionAndOptionalObjectTupleGuard(op: unknown[]): op is [strs: string[], fn: (val: any) => R, obj?: object]; declare function pipeFromArray(fns: Array>): UnaryFunction; declare function safePluck(stateObject: T, keys: K1 | [K1]): T[K1]; declare function safePluck(stateObject: T, keys: [K1, K2]): T[K1][K2]; declare function safePluck(stateObject: T, keys: [K1, K2, K3]): T[K1][K2][K3]; declare function safePluck(stateObject: T, keys: [K1, K2, K3, K4]): T[K1][K2][K3][K4]; declare function safePluck(stateObject: T, keys: [K1, K2, K3, K4, K5]): T[K1][K2][K3][K4][K5]; declare function safePluck(stateObject: T, keys: [K1] | [K1, K2] | [K1, K2, K3] | [K1, K2, K3, K4] | [K1, K2, K3, K4, K5] | [K1, K2, K3, K4, K5, K6]): T[K1][K2][K3][K4][K5][K6]; export { createAccumulationObservable, createSideEffectObservable, defaultAccumulator, distinctUntilSomeChanged, isDefined, isKeyOf, isObjectGuard, isOperateFnArrayGuard, isStringAndFunctionTupleGuard, isStringArrayFunctionAndOptionalObjectTupleGuard, isStringArrayGuard, pipeFromArray, safePluck, select, selectSlice, stateful }; export type { AccumulationFn, Accumulator, CompareFn, KeyCompareMap, PickSlice }; //# sourceMappingURL=state-selections.d.ts.map