source: trip-planner-front/node_modules/rxjs/src/internal/util/subscribeTo.ts

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

initial commit

  • Property mode set to 100644
File size: 1.4 KB
Line 
1import { ObservableInput } from '../types';
2import { subscribeToArray } from './subscribeToArray';
3import { subscribeToPromise } from './subscribeToPromise';
4import { subscribeToIterable } from './subscribeToIterable';
5import { subscribeToObservable } from './subscribeToObservable';
6import { isArrayLike } from './isArrayLike';
7import { isPromise } from './isPromise';
8import { isObject } from './isObject';
9import { iterator as Symbol_iterator } from '../symbol/iterator';
10import { observable as Symbol_observable } from '../symbol/observable';
11import { Subscription } from '../Subscription';
12import { Subscriber } from '../Subscriber';
13
14export const subscribeTo = <T>(result: ObservableInput<T>): (subscriber: Subscriber<T>) => Subscription | void => {
15 if (!!result && typeof result[Symbol_observable] === 'function') {
16 return subscribeToObservable(result as any);
17 } else if (isArrayLike(result)) {
18 return subscribeToArray(result);
19 } else if (isPromise(result)) {
20 return subscribeToPromise(result as Promise<any>);
21 } else if (!!result && typeof result[Symbol_iterator] === 'function') {
22 return subscribeToIterable(result as any);
23 } else {
24 const value = isObject(result) ? 'an invalid object' : `'${result}'`;
25 const msg = `You provided ${value} where a stream was expected.`
26 + ' You can provide an Observable, Promise, Array, or Iterable.';
27 throw new TypeError(msg);
28 }
29};
Note: See TracBrowser for help on using the repository browser.