source: trip-planner-front/node_modules/rxjs/internal/operators/distinct.d.ts@ bdd6491

Last change on this file since bdd6491 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.0 KB
Line 
1import { Observable } from '../Observable';
2import { Subscriber } from '../Subscriber';
3import { MonoTypeOperatorFunction } from '../types';
4import { SimpleOuterSubscriber } from '../innerSubscribe';
5/**
6 * Returns an Observable that emits all items emitted by the source Observable that are distinct by comparison from previous items.
7 *
8 * If a keySelector function is provided, then it will project each value from the source observable into a new value that it will
9 * check for equality with previously projected values. If a keySelector function is not provided, it will use each value from the
10 * source observable directly with an equality check against previous values.
11 *
12 * In JavaScript runtimes that support `Set`, this operator will use a `Set` to improve performance of the distinct value checking.
13 *
14 * In other runtimes, this operator will use a minimal implementation of `Set` that relies on an `Array` and `indexOf` under the
15 * hood, so performance will degrade as more values are checked for distinction. Even in newer browsers, a long-running `distinct`
16 * use might result in memory leaks. To help alleviate this in some scenarios, an optional `flushes` parameter is also provided so
17 * that the internal `Set` can be "flushed", basically clearing it of values.
18 *
19 * ## Examples
20 * A simple example with numbers
21 * ```ts
22 * import { of } from 'rxjs';
23 * import { distinct } from 'rxjs/operators';
24 *
25 * of(1, 1, 2, 2, 2, 1, 2, 3, 4, 3, 2, 1).pipe(
26 * distinct(),
27 * )
28 * .subscribe(x => console.log(x)); // 1, 2, 3, 4
29 * ```
30 *
31 * An example using a keySelector function
32 * ```typescript
33 * import { of } from 'rxjs';
34 * import { distinct } from 'rxjs/operators';
35 *
36 * interface Person {
37 * age: number,
38 * name: string
39 * }
40 *
41 * of<Person>(
42 * { age: 4, name: 'Foo'},
43 * { age: 7, name: 'Bar'},
44 * { age: 5, name: 'Foo'},
45 * ).pipe(
46 * distinct((p: Person) => p.name),
47 * )
48 * .subscribe(x => console.log(x));
49 *
50 * // displays:
51 * // { age: 4, name: 'Foo' }
52 * // { age: 7, name: 'Bar' }
53 * ```
54 * @see {@link distinctUntilChanged}
55 * @see {@link distinctUntilKeyChanged}
56 *
57 * @param {function} [keySelector] Optional function to select which value you want to check as distinct.
58 * @param {Observable} [flushes] Optional Observable for flushing the internal HashSet of the operator.
59 * @return {Observable} An Observable that emits items from the source Observable with distinct values.
60 * @method distinct
61 * @owner Observable
62 */
63export declare function distinct<T, K>(keySelector?: (value: T) => K, flushes?: Observable<any>): MonoTypeOperatorFunction<T>;
64/**
65 * We need this JSDoc comment for affecting ESDoc.
66 * @ignore
67 * @extends {Ignored}
68 */
69export declare class DistinctSubscriber<T, K> extends SimpleOuterSubscriber<T, T> {
70 private keySelector?;
71 private values;
72 constructor(destination: Subscriber<T>, keySelector?: (value: T) => K, flushes?: Observable<any>);
73 notifyNext(): void;
74 notifyError(error: any): void;
75 protected _next(value: T): void;
76 private _useKeySelector;
77 private _finalizeNext;
78}
Note: See TracBrowser for help on using the repository browser.