UNPKG

1.98 kBTypeScriptView Raw
1import { Observable } from '../Observable';
2import { ObservableInput, OperatorFunction } from '../types';
3/**
4 * Branch out the source Observable values as a nested Observable using a
5 * factory function of closing Observables to determine when to start a new
6 * window.
7 *
8 * <span class="informal">It's like {@link bufferWhen}, but emits a nested
9 * Observable instead of an array.</span>
10 *
11 * ![](windowWhen.png)
12 *
13 * Returns an Observable that emits windows of items it collects from the source
14 * Observable. The output Observable emits connected, non-overlapping windows.
15 * It emits the current window and opens a new one whenever the Observable
16 * produced by the specified `closingSelector` function emits an item. The first
17 * window is opened immediately when subscribing to the output Observable.
18 *
19 * ## Example
20 *
21 * Emit only the first two clicks events in every window of [1-5] random seconds
22 *
23 * ```ts
24 * import { fromEvent, windowWhen, interval, map, take, mergeAll } from 'rxjs';
25 *
26 * const clicks = fromEvent(document, 'click');
27 * const result = clicks.pipe(
28 * windowWhen(() => interval(1000 + Math.random() * 4000)),
29 * map(win => win.pipe(take(2))), // take at most 2 emissions from each window
30 * mergeAll() // flatten the Observable-of-Observables
31 * );
32 * result.subscribe(x => console.log(x));
33 * ```
34 *
35 * @see {@link window}
36 * @see {@link windowCount}
37 * @see {@link windowTime}
38 * @see {@link windowToggle}
39 * @see {@link bufferWhen}
40 *
41 * @param {function(): Observable} closingSelector A function that takes no
42 * arguments and returns an Observable that signals (on either `next` or
43 * `complete`) when to close the previous window and start a new one.
44 * @return A function that returns an Observable of windows, which in turn are
45 * Observables.
46 */
47export declare function windowWhen<T>(closingSelector: () => ObservableInput<any>): OperatorFunction<T, Observable<T>>;
48//# sourceMappingURL=windowWhen.d.ts.map
\No newline at end of file