UNPKG

2.01 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 * Emit only the first two clicks events in every window of [1-5] random seconds
21 * ```ts
22 * import { fromEvent, interval } from 'rxjs';
23 * import { windowWhen, map, mergeAll, take } from 'rxjs/operators';
24 *
25 * const clicks = fromEvent(document, 'click');
26 * const result = clicks.pipe(
27 * windowWhen(() => interval(1000 + Math.random() * 4000)),
28 * map(win => win.pipe(take(2))), // each window has at most 2 emissions
29 * mergeAll() // flatten the Observable-of-Observables
30 * );
31 * result.subscribe(x => console.log(x));
32 * ```
33 *
34 * @see {@link window}
35 * @see {@link windowCount}
36 * @see {@link windowTime}
37 * @see {@link windowToggle}
38 * @see {@link bufferWhen}
39 *
40 * @param {function(): Observable} closingSelector A function that takes no
41 * arguments and returns an Observable that signals (on either `next` or
42 * `complete`) when to close the previous window and start a new one.
43 * @return A function that returns an Observable of windows, which in turn are
44 * Observables.
45 */
46export declare function windowWhen<T>(closingSelector: () => ObservableInput<any>): OperatorFunction<T, Observable<T>>;
47//# sourceMappingURL=windowWhen.d.ts.map
\No newline at end of file