1 | import { Observable } from '../Observable';
|
---|
2 | import { SchedulerAction, SchedulerLike } from '../types';
|
---|
3 | import { Subscriber } from '../Subscriber';
|
---|
4 | import { Subscription } from '../Subscription';
|
---|
5 | /**
|
---|
6 | * Convert an object into an Observable of `[key, value]` pairs.
|
---|
7 | *
|
---|
8 | * <span class="informal">Turn entries of an object into a stream.</span>
|
---|
9 | *
|
---|
10 | * <img src="./img/pairs.png" width="100%">
|
---|
11 | *
|
---|
12 | * `pairs` takes an arbitrary object and returns an Observable that emits arrays. Each
|
---|
13 | * emitted array has exactly two elements - the first is a key from the object
|
---|
14 | * and the second is a value corresponding to that key. Keys are extracted from
|
---|
15 | * an object via `Object.keys` function, which means that they will be only
|
---|
16 | * enumerable keys that are present on an object directly - not ones inherited
|
---|
17 | * via prototype chain.
|
---|
18 | *
|
---|
19 | * By default these arrays are emitted synchronously. To change that you can
|
---|
20 | * pass a {@link SchedulerLike} as a second argument to `pairs`.
|
---|
21 | *
|
---|
22 | * @example <caption>Converts a javascript object to an Observable</caption>
|
---|
23 | * ```ts
|
---|
24 | * import { pairs } from 'rxjs';
|
---|
25 | *
|
---|
26 | * const obj = {
|
---|
27 | * foo: 42,
|
---|
28 | * bar: 56,
|
---|
29 | * baz: 78
|
---|
30 | * };
|
---|
31 | *
|
---|
32 | * pairs(obj)
|
---|
33 | * .subscribe(
|
---|
34 | * value => console.log(value),
|
---|
35 | * err => {},
|
---|
36 | * () => console.log('the end!')
|
---|
37 | * );
|
---|
38 | *
|
---|
39 | * // Logs:
|
---|
40 | * // ["foo", 42],
|
---|
41 | * // ["bar", 56],
|
---|
42 | * // ["baz", 78],
|
---|
43 | * // "the end!"
|
---|
44 | * ```
|
---|
45 | *
|
---|
46 | * @param {Object} obj The object to inspect and turn into an
|
---|
47 | * Observable sequence.
|
---|
48 | * @param {Scheduler} [scheduler] An optional IScheduler to schedule
|
---|
49 | * when resulting Observable will emit values.
|
---|
50 | * @returns {(Observable<Array<string|T>>)} An observable sequence of
|
---|
51 | * [key, value] pairs from the object.
|
---|
52 | */
|
---|
53 | export declare function pairs<T>(obj: Object, scheduler?: SchedulerLike): Observable<[string, T]>;
|
---|
54 | /** @internal */
|
---|
55 | export declare function dispatch<T>(this: SchedulerAction<any>, state: {
|
---|
56 | keys: string[];
|
---|
57 | index: number;
|
---|
58 | subscriber: Subscriber<[string, T]>;
|
---|
59 | subscription: Subscription;
|
---|
60 | obj: Object;
|
---|
61 | }): void;
|
---|