Skip to content

Commit

Permalink
fix(symbol/observable): will be exported as observable to better supp…
Browse files Browse the repository at this point in the history
…ort Babel UMD and others

To migrate the code follow the example bellow:

Before:

import { $$observable } from 'rxjs/symbol/observable';

After:

import { observable } from 'rxjs/symbol/observable';

Closes ReactiveX#2415
  • Loading branch information
DzmitryShylovich committed Mar 15, 2017
1 parent e4e7a18 commit 0fd8647
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { root } from './util/root';
import { toSubscriber } from './util/toSubscriber';
import { IfObservable } from './observable/IfObservable';
import { ErrorObservable } from './observable/ErrorObservable';
import { $$observable } from './symbol/observable';
import { observable as Symbol_observable } from './symbol/observable';

export interface Subscribable<T> {
subscribe(observerOrNext?: PartialObserver<T> | ((value: T) => void),
Expand Down Expand Up @@ -177,7 +177,7 @@ export class Observable<T> implements Subscribable<T> {
* @method Symbol.observable
* @return {Observable} this instance of the observable
*/
[$$observable]() {
[Symbol_observable]() {
return this;
}
}
2 changes: 1 addition & 1 deletion src/Rx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ import { QueueScheduler } from './scheduler/QueueScheduler';
import { AnimationFrameScheduler } from './scheduler/AnimationFrameScheduler';
import { $$rxSubscriber as rxSubscriber } from './symbol/rxSubscriber';
import { $$iterator as iterator } from './symbol/iterator';
import { $$observable as observable } from './symbol/observable';
import { observable } from './symbol/observable';

/* tslint:enable:no-unused-variable */

Expand Down
8 changes: 4 additions & 4 deletions src/observable/FromObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { $$iterator } from '../symbol/iterator';
import { Observable, ObservableInput } from '../Observable';
import { Subscriber } from '../Subscriber';
import { ObserveOnSubscriber } from '../operator/observeOn';
import { $$observable } from '../symbol/observable';
import { observable as Symbol_observable } from '../symbol/observable';

/**
* We need this JSDoc comment for affecting ESDoc.
Expand Down Expand Up @@ -84,7 +84,7 @@ export class FromObservable<T> extends Observable<T> {
*/
static create<T>(ish: ObservableInput<T>, scheduler?: IScheduler): Observable<T> {
if (ish != null) {
if (typeof ish[$$observable] === 'function') {
if (typeof ish[Symbol_observable] === 'function') {
if (ish instanceof Observable && !scheduler) {
return ish;
}
Expand All @@ -107,9 +107,9 @@ export class FromObservable<T> extends Observable<T> {
const ish = this.ish;
const scheduler = this.scheduler;
if (scheduler == null) {
return ish[$$observable]().subscribe(subscriber);
return ish[Symbol_observable]().subscribe(subscriber);
} else {
return ish[$$observable]().subscribe(new ObserveOnSubscriber(subscriber, scheduler, 0));
return ish[Symbol_observable]().subscribe(new ObserveOnSubscriber(subscriber, scheduler, 0));
}
}
}
7 changes: 6 additions & 1 deletion src/symbol/observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ export function getSymbolObservable(context: any) {
return $$observable;
}

export const $$observable = getSymbolObservable(root);
export const observable = getSymbolObservable(root);

/**
* @deprecated use observable instead
*/
export const $$observable = observable;
6 changes: 3 additions & 3 deletions src/util/subscribeToResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { $$iterator } from '../symbol/iterator';
import { Subscription } from '../Subscription';
import { InnerSubscriber } from '../InnerSubscriber';
import { OuterSubscriber } from '../OuterSubscriber';
import { $$observable } from '../symbol/observable';
import { observable as Symbol_observable } from '../symbol/observable';

export function subscribeToResult<T, R>(outerSubscriber: OuterSubscriber<T, R>,
result: any,
Expand Down Expand Up @@ -67,8 +67,8 @@ export function subscribeToResult<T>(outerSubscriber: OuterSubscriber<any, any>,
break;
}
} while (true);
} else if (result && typeof result[$$observable] === 'function') {
const obs = result[$$observable]();
} else if (result && typeof result[Symbol_observable] === 'function') {
const obs = result[Symbol_observable]();
if (typeof obs.subscribe !== 'function') {
destination.error(new TypeError('Provided object does not correctly implement Symbol.observable'));
} else {
Expand Down

0 comments on commit 0fd8647

Please sign in to comment.