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:
666 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | import { Subscriber } from '../Subscriber';
|
---|
| 2 | import { observable as Symbol_observable } from '../symbol/observable';
|
---|
| 3 |
|
---|
| 4 | /**
|
---|
| 5 | * Subscribes to an object that implements Symbol.observable with the given
|
---|
| 6 | * Subscriber.
|
---|
| 7 | * @param obj An object that implements Symbol.observable
|
---|
| 8 | */
|
---|
| 9 | export const subscribeToObservable = <T>(obj: any) => (subscriber: Subscriber<T>) => {
|
---|
| 10 | const obs = obj[Symbol_observable]();
|
---|
| 11 | if (typeof obs.subscribe !== 'function') {
|
---|
| 12 | // Should be caught by observable subscribe function error handling.
|
---|
| 13 | throw new TypeError('Provided object does not correctly implement Symbol.observable');
|
---|
| 14 | } else {
|
---|
| 15 | return obs.subscribe(subscriber);
|
---|
| 16 | }
|
---|
| 17 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.