From 747bef6adfc5d36e1465ecf2752a7cb470ad5142 Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Mon, 3 Apr 2017 22:55:00 +0300 Subject: [PATCH] feat(symbol exports): symbols now also exported without `$$` prefix to work with Babel UMD exporting (#2435) * fix(symbol/observable): will be exported as observable to better support 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 #2415 * fix(symbol/iterator): will be exported as iterator to better support Babel UMD and others To migrate the code follow the example bellow: Before: import { $$iterator } from 'rxjs/symbol/iterator'; After: import { iterator } from 'rxjs/symbol/iterator'; * fix(symbol/rxSubscriber): will be exported as rxSubscriber to better support Babel UMD and others To migrate the code follow the example bellow: Before: import { $$rxSubscriber } from 'rxjs/symbol/rxSubscriber'; After: import { rxSubscriber } from 'rxjs/symbol/rxSubscriber'; --- src/Observable.ts | 4 ++-- src/Rx.ts | 6 +++--- src/Subject.ts | 4 ++-- src/Subscriber.ts | 4 ++-- src/observable/FromObservable.ts | 12 ++++++------ src/observable/IteratorObservable.ts | 10 +++++----- src/operator/zip.ts | 10 +++++----- src/symbol/iterator.ts | 7 ++++++- src/symbol/observable.ts | 7 ++++++- src/symbol/rxSubscriber.ts | 7 ++++++- src/util/subscribeToResult.ts | 12 ++++++------ src/util/toSubscriber.ts | 6 +++--- 12 files changed, 52 insertions(+), 37 deletions(-) diff --git a/src/Observable.ts b/src/Observable.ts index 0aa4b4cef3..e231ed9309 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -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 { subscribe(observerOrNext?: PartialObserver | ((value: T) => void), @@ -177,7 +177,7 @@ export class Observable implements Subscribable { * @method Symbol.observable * @return {Observable} this instance of the observable */ - [$$observable]() { + [Symbol_observable]() { return this; } } diff --git a/src/Rx.ts b/src/Rx.ts index b04c99c505..3bebef958c 100644 --- a/src/Rx.ts +++ b/src/Rx.ts @@ -169,9 +169,9 @@ import { AsapScheduler } from './scheduler/AsapScheduler'; import { AsyncScheduler } from './scheduler/AsyncScheduler'; 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 { rxSubscriber } from './symbol/rxSubscriber'; +import { iterator } from './symbol/iterator'; +import { observable } from './symbol/observable'; /* tslint:enable:no-unused-variable */ diff --git a/src/Subject.ts b/src/Subject.ts index 8dae4c86d5..b3229f9050 100644 --- a/src/Subject.ts +++ b/src/Subject.ts @@ -5,7 +5,7 @@ import { Subscriber } from './Subscriber'; import { ISubscription, Subscription, TeardownLogic } from './Subscription'; import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError'; import { SubjectSubscription } from './SubjectSubscription'; -import { $$rxSubscriber } from './symbol/rxSubscriber'; +import { rxSubscriber as rxSubscriberSymbol } from './symbol/rxSubscriber'; /** * @class SubjectSubscriber @@ -21,7 +21,7 @@ export class SubjectSubscriber extends Subscriber { */ export class Subject extends Observable implements ISubscription { - [$$rxSubscriber]() { + [rxSubscriberSymbol]() { return new SubjectSubscriber(this); } diff --git a/src/Subscriber.ts b/src/Subscriber.ts index 8ef868f24f..bcbd38b458 100644 --- a/src/Subscriber.ts +++ b/src/Subscriber.ts @@ -2,7 +2,7 @@ import { isFunction } from './util/isFunction'; import { Observer, PartialObserver } from './Observer'; import { Subscription } from './Subscription'; import { empty as emptyObserver } from './Observer'; -import { $$rxSubscriber } from './symbol/rxSubscriber'; +import { rxSubscriber as rxSubscriberSymbol } from './symbol/rxSubscriber'; /** * Implements the {@link Observer} interface and extends the @@ -16,7 +16,7 @@ import { $$rxSubscriber } from './symbol/rxSubscriber'; */ export class Subscriber extends Subscription implements Observer { - [$$rxSubscriber]() { return this; } + [rxSubscriberSymbol]() { return this; } /** * A static factory for a Subscriber, given a (potentially partial) definition diff --git a/src/observable/FromObservable.ts b/src/observable/FromObservable.ts index 5e9bf48953..f1de29590b 100644 --- a/src/observable/FromObservable.ts +++ b/src/observable/FromObservable.ts @@ -7,11 +7,11 @@ import { ArrayObservable } from './ArrayObservable'; import { ArrayLikeObservable } from './ArrayLikeObservable'; import { IScheduler } from '../Scheduler'; -import { $$iterator } from '../symbol/iterator'; +import { iterator as Symbol_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. @@ -84,7 +84,7 @@ export class FromObservable extends Observable { */ static create(ish: ObservableInput, scheduler?: IScheduler): Observable { if (ish != null) { - if (typeof ish[$$observable] === 'function') { + if (typeof ish[Symbol_observable] === 'function') { if (ish instanceof Observable && !scheduler) { return ish; } @@ -93,7 +93,7 @@ export class FromObservable extends Observable { return new ArrayObservable(ish, scheduler); } else if (isPromise(ish)) { return new PromiseObservable(ish, scheduler); - } else if (typeof ish[$$iterator] === 'function' || typeof ish === 'string') { + } else if (typeof ish[Symbol_iterator] === 'function' || typeof ish === 'string') { return new IteratorObservable(ish, scheduler); } else if (isArrayLike(ish)) { return new ArrayLikeObservable(ish, scheduler); @@ -107,9 +107,9 @@ export class FromObservable extends Observable { 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)); } } } diff --git a/src/observable/IteratorObservable.ts b/src/observable/IteratorObservable.ts index 401d23a6a0..5bc3f8897c 100644 --- a/src/observable/IteratorObservable.ts +++ b/src/observable/IteratorObservable.ts @@ -1,7 +1,7 @@ import { root } from '../util/root'; import { IScheduler } from '../Scheduler'; import { Observable } from '../Observable'; -import { $$iterator } from '../symbol/iterator'; +import { iterator as Symbol_iterator } from '../symbol/iterator'; import { TeardownLogic } from '../Subscription'; import { Subscriber } from '../Subscriber'; @@ -89,7 +89,7 @@ class StringIterator { private idx: number = 0, private len: number = str.length) { } - [$$iterator]() { return (this); } + [Symbol_iterator]() { return (this); } next() { return this.idx < this.len ? { done: false, @@ -106,7 +106,7 @@ class ArrayIterator { private idx: number = 0, private len: number = toLength(arr)) { } - [$$iterator]() { return this; } + [Symbol_iterator]() { return this; } next() { return this.idx < this.len ? { done: false, @@ -119,7 +119,7 @@ class ArrayIterator { } function getIterator(obj: any) { - const i = obj[$$iterator]; + const i = obj[Symbol_iterator]; if (!i && typeof obj === 'string') { return new StringIterator(obj); } @@ -129,7 +129,7 @@ function getIterator(obj: any) { if (!i) { throw new TypeError('object is not iterable'); } - return obj[$$iterator](); + return obj[Symbol_iterator](); } const maxSafeInteger = Math.pow(2, 53) - 1; diff --git a/src/operator/zip.ts b/src/operator/zip.ts index 7358488966..afa7089f11 100644 --- a/src/operator/zip.ts +++ b/src/operator/zip.ts @@ -7,7 +7,7 @@ import { Subscriber } from '../Subscriber'; import { OuterSubscriber } from '../OuterSubscriber'; import { InnerSubscriber } from '../InnerSubscriber'; import { subscribeToResult } from '../util/subscribeToResult'; -import { $$iterator } from '../symbol/iterator'; +import { iterator as Symbol_iterator } from '../symbol/iterator'; /* tslint:disable:max-line-length */ export function zipProto(this: Observable, project: (v1: T) => R): Observable; @@ -135,8 +135,8 @@ export class ZipSubscriber extends Subscriber { const iterators = this.iterators; if (isArray(value)) { iterators.push(new StaticArrayIterator(value)); - } else if (typeof value[$$iterator] === 'function') { - iterators.push(new StaticIterator(value[$$iterator]())); + } else if (typeof value[Symbol_iterator] === 'function') { + iterators.push(new StaticIterator(value[Symbol_iterator]())); } else { iterators.push(new ZipBufferIterator(this.destination, this, value)); } @@ -261,7 +261,7 @@ class StaticArrayIterator implements LookAheadIterator { this.length = array.length; } - [$$iterator]() { + [Symbol_iterator]() { return this; } @@ -296,7 +296,7 @@ class ZipBufferIterator extends OuterSubscriber implements LookAhead super(destination); } - [$$iterator]() { + [Symbol_iterator]() { return this; } diff --git a/src/symbol/iterator.ts b/src/symbol/iterator.ts index 3b689a7c89..cdee34a606 100644 --- a/src/symbol/iterator.ts +++ b/src/symbol/iterator.ts @@ -30,4 +30,9 @@ export function symbolIteratorPonyfill(root: any) { } } -export const $$iterator = symbolIteratorPonyfill(root); \ No newline at end of file +export const iterator = symbolIteratorPonyfill(root); + +/** + * @deprecated use iterator instead + */ +export const $$iterator = iterator; diff --git a/src/symbol/observable.ts b/src/symbol/observable.ts index 19809d50b4..06c2bfb556 100644 --- a/src/symbol/observable.ts +++ b/src/symbol/observable.ts @@ -18,4 +18,9 @@ export function getSymbolObservable(context: any) { return $$observable; } -export const $$observable = getSymbolObservable(root); \ No newline at end of file +export const observable = getSymbolObservable(root); + +/** + * @deprecated use observable instead + */ +export const $$observable = observable; diff --git a/src/symbol/rxSubscriber.ts b/src/symbol/rxSubscriber.ts index fc7630842d..693d0a9881 100644 --- a/src/symbol/rxSubscriber.ts +++ b/src/symbol/rxSubscriber.ts @@ -2,5 +2,10 @@ import { root } from '../util/root'; const Symbol: any = root.Symbol; -export const $$rxSubscriber = (typeof Symbol === 'function' && typeof Symbol.for === 'function') ? +export const rxSubscriber = (typeof Symbol === 'function' && typeof Symbol.for === 'function') ? Symbol.for('rxSubscriber') : '@@rxSubscriber'; + +/** + * @deprecated use rxSubscriber instead + */ +export const $$rxSubscriber = rxSubscriber; diff --git a/src/util/subscribeToResult.ts b/src/util/subscribeToResult.ts index 29af49afa5..ae19fe5795 100644 --- a/src/util/subscribeToResult.ts +++ b/src/util/subscribeToResult.ts @@ -4,11 +4,11 @@ import { isPromise } from './isPromise'; import { isObject } from './isObject'; import { Subscriber } from '../Subscriber'; import { Observable, ObservableInput } from '../Observable'; -import { $$iterator } from '../symbol/iterator'; +import { iterator as Symbol_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(outerSubscriber: OuterSubscriber, result: any, @@ -54,8 +54,8 @@ export function subscribeToResult(outerSubscriber: OuterSubscriber, root.setTimeout(() => { throw err; }); }); return destination; - } else if (result && typeof result[$$iterator] === 'function') { - const iterator = result[$$iterator](); + } else if (result && typeof result[Symbol_iterator] === 'function') { + const iterator = result[Symbol_iterator](); do { let item = iterator.next(); if (item.done) { @@ -67,8 +67,8 @@ export function subscribeToResult(outerSubscriber: OuterSubscriber, 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 { diff --git a/src/util/toSubscriber.ts b/src/util/toSubscriber.ts index 53c73f4781..134fa56b17 100644 --- a/src/util/toSubscriber.ts +++ b/src/util/toSubscriber.ts @@ -1,5 +1,5 @@ import { Subscriber } from '../Subscriber'; -import { $$rxSubscriber } from '../symbol/rxSubscriber'; +import { rxSubscriber as rxSubscriberSymbol } from '../symbol/rxSubscriber'; import { PartialObserver, empty as emptyObserver } from '../Observer'; export function toSubscriber( @@ -12,8 +12,8 @@ export function toSubscriber( return (> nextOrObserver); } - if (nextOrObserver[$$rxSubscriber]) { - return nextOrObserver[$$rxSubscriber](); + if (nextOrObserver[rxSubscriberSymbol]) { + return nextOrObserver[rxSubscriberSymbol](); } }