diff --git a/spec/observables/from-spec.js b/spec/observables/from-spec.js index e9be43826e..42f6e578f5 100644 --- a/spec/observables/from-spec.js +++ b/spec/observables/from-spec.js @@ -2,7 +2,7 @@ var Rx = require('../../dist/cjs/Rx'); var Promise = require('promise'); var Observable = Rx.Observable; -var $$iterator = require('../../dist/cjs/util/Symbol_iterator').$$iterator; +var $$iterator = require('../../dist/cjs/util/SymbolShim').SymbolShim.iterator; describe('Observable.from', function () { it('should enumerate an Array', function (done) { diff --git a/src/Observable.ts b/src/Observable.ts index e2ca62ee7a..72ce5186e6 100644 --- a/src/Observable.ts +++ b/src/Observable.ts @@ -5,7 +5,7 @@ import {Subscriber} from './Subscriber'; import {Subscription} from './Subscription'; import {root} from './util/root'; import {CoreOperators } from './CoreOperators'; -import {$$observable} from './util/Symbol_observable'; +import {SymbolShim} from './util/SymbolShim'; import {GroupedObservable} from './operators/groupBy-support'; import {ConnectableObservable} from './observable/ConnectableObservable'; import {Subject} from './Subject'; @@ -67,7 +67,7 @@ export class Observable implements CoreOperators { * @returns {Observable} this instance of the observable * @description an interop point defined by the es7-observable spec https://github.com/zenparsing/es-observable */ - [$$observable]() { + [SymbolShim.observable]() { return this; } diff --git a/src/observable/IteratorObservable.ts b/src/observable/IteratorObservable.ts index 5aae9b89f1..e35707c882 100644 --- a/src/observable/IteratorObservable.ts +++ b/src/observable/IteratorObservable.ts @@ -2,7 +2,7 @@ import {Scheduler} from '../Scheduler'; import {Observable} from '../Observable'; import {root} from '../util/root'; -import {$$iterator} from '../util/Symbol_iterator'; +import {SymbolShim} from '../util/SymbolShim'; import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; @@ -105,7 +105,7 @@ class StringIterator { private idx: number = 0, private len: number = str.length) { } - [$$iterator]() { return (this); } + [SymbolShim.iterator]() { return (this); } next() { return this.idx < this.len ? { done: false, @@ -122,7 +122,7 @@ class ArrayIterator { private idx: number = 0, private len: number = toLength(arr)) { } - [$$iterator]() { return this; } + [SymbolShim.iterator]() { return this; } next() { return this.idx < this.len ? { done: false, @@ -135,7 +135,7 @@ class ArrayIterator { } function getIterator(obj: any) { - const i = obj[$$iterator]; + const i = obj[SymbolShim.iterator]; if (!i && typeof obj === 'string') { return new StringIterator(obj); } @@ -145,7 +145,7 @@ function getIterator(obj: any) { if (!i) { throw new TypeError('Object is not iterable'); } - return obj[$$iterator](); + return obj[SymbolShim.iterator](); } const maxSafeInteger = Math.pow(2, 53) - 1; diff --git a/src/observable/from.ts b/src/observable/from.ts index e84bcd14fb..d3886272c4 100644 --- a/src/observable/from.ts +++ b/src/observable/from.ts @@ -3,8 +3,7 @@ import {IteratorObservable} from'./IteratorObservable'; import {ArrayObservable} from './fromArray'; import {Scheduler} from '../Scheduler'; -import {$$observable} from '../util/Symbol_observable'; -import {$$iterator} from '../util/Symbol_iterator'; +import {SymbolShim} from '../util/SymbolShim'; import {Observable} from '../Observable'; import {Subscriber} from '../Subscriber'; import {ObserveOnSubscriber} from '../operators/observeOn-support'; @@ -23,12 +22,12 @@ export class FromObservable extends Observable { return new ArrayObservable(ish, scheduler); } else if (typeof ish.then === 'function') { return new PromiseObservable(ish, scheduler); - } else if (typeof ish[$$observable] === 'function') { + } else if (typeof ish[SymbolShim.observable] === 'function') { if (ish instanceof Observable) { return ish; } return new FromObservable(ish, scheduler); - } else if (typeof ish[$$iterator] === 'function') { + } else if (typeof ish[SymbolShim.iterator] === 'function') { return new IteratorObservable(ish, null, null, scheduler); } } @@ -40,9 +39,9 @@ export class FromObservable extends Observable { const ish = this.ish; const scheduler = this.scheduler; if (scheduler === immediate) { - return ish[$$observable]().subscribe(subscriber); + return ish[SymbolShim.observable]().subscribe(subscriber); } else { - return ish[$$observable]().subscribe(new ObserveOnSubscriber(subscriber, scheduler, 0)); + return ish[SymbolShim.observable]().subscribe(new ObserveOnSubscriber(subscriber, scheduler, 0)); } } } diff --git a/src/operators/zip-support.ts b/src/operators/zip-support.ts index 0dfcb993fe..5750c58fe7 100644 --- a/src/operators/zip-support.ts +++ b/src/operators/zip-support.ts @@ -6,7 +6,7 @@ import {tryCatch} from '../util/tryCatch'; import {errorObject} from '../util/errorObject'; import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; -import {$$iterator} from '../util/Symbol_iterator'; +import {SymbolShim} from '../util/SymbolShim'; const isArray = Array.isArray; @@ -43,8 +43,8 @@ export class ZipSubscriber extends Subscriber { const index = this.index++; if (isArray(value)) { iterators.push(new StaticArrayIterator(value)); - } else if (typeof value[$$iterator] === 'function') { - iterators.push(new StaticIterator(value[$$iterator]())); + } else if (typeof value[SymbolShim.iterator] === 'function') { + iterators.push(new StaticIterator(value[SymbolShim.iterator]())); } else { iterators.push(new ZipBufferIterator(this.destination, this, value, index)); } @@ -158,7 +158,7 @@ class StaticArrayIterator implements LookAheadIterator { this.length = array.length; } - [$$iterator]() { + [SymbolShim.iterator]() { return this; } @@ -189,7 +189,7 @@ class ZipBufferIterator extends OuterSubscriber implements LookAhead super(destination); } - [$$iterator]() { + [SymbolShim.iterator]() { return this; } diff --git a/src/util/Symbol_iterator.ts b/src/util/SymbolShim.ts similarity index 55% rename from src/util/Symbol_iterator.ts rename to src/util/SymbolShim.ts index 48b9230e1e..f2aed6ec94 100644 --- a/src/util/Symbol_iterator.ts +++ b/src/util/SymbolShim.ts @@ -1,36 +1,48 @@ -import {root} from './root'; - -if (!root.Symbol) { - root.Symbol = {}; -} - -if (!root.Symbol.iterator) { - if (typeof root.Symbol.for === 'function') { - root.Symbol.iterator = root.Symbol.for('iterator'); - } else if (root.Set && typeof new root.Set()['@@iterator'] === 'function') { - // Bug for mozilla version - root.Symbol.iterator = '@@iterator'; - } else if (root.Map) { - // es6-shim specific logic - let keys = Object.getOwnPropertyNames(root.Map.prototype); - for (let i = 0; i < keys.length; ++i) { - let key = keys[i]; - if (key !== 'entries' && key !== 'size' && root.Map.prototype[key] === root.Map.prototype['entries']) { - root.Symbol.iterator = key; - break; - } - } - } else { - root.Symbol.iterator = '@@iterator'; - } -} - -export const $$iterator = root.Symbol.iterator; - -// // Shim in iterator support -// export var $iterator$ = (typeof Symbol === 'function' && Symbol.iterator) || '_es6shim_iterator_'; - -// // Bug for mozilla version -// if (root.Set && typeof new root.Set()['@@iterator'] === 'function') { -// $iterator$ = '@@iterator'; -// } +import {root} from './root'; + +if (!root.Symbol) { + root.Symbol = {}; +} + +if (!root.Symbol.observable) { + if (typeof root.Symbol.for === 'function') { + root.Symbol.observable = root.Symbol.for('observable'); + } else { + root.Symbol.observable = '@@observable'; + } +} + +if (!root.Symbol.iterator) { + if (typeof root.Symbol.for === 'function') { + root.Symbol.iterator = root.Symbol.for('iterator'); + } else if (root.Set && typeof new root.Set()['@@iterator'] === 'function') { + // Bug for mozilla version + root.Symbol.iterator = '@@iterator'; + } else if (root.Map) { + // es6-shim specific logic + let keys = Object.getOwnPropertyNames(root.Map.prototype); + for (let i = 0; i < keys.length; ++i) { + let key = keys[i]; + if (key !== 'entries' && key !== 'size' && root.Map.prototype[key] === root.Map.prototype['entries']) { + root.Symbol.iterator = key; + break; + } + } + } else { + root.Symbol.iterator = '@@iterator'; + } +} + +if (!root.Symbol.dispose) { + if (typeof root.Symbol.for === 'function') { + root.Symbol.dispose = root.Symbol.for('dispose'); + } else { + root.Symbol.dispose = '@@dispose'; + } +} + +export module SymbolShim { + export const observable: symbol = root.Symbol.observable; + export const iterator: symbol = root.Symbol.iterator; + export const dispose: symbol = root.Symbol.dispose; +}; \ No newline at end of file diff --git a/src/util/Symbol_dispose.ts b/src/util/Symbol_dispose.ts deleted file mode 100644 index 370ca96b89..0000000000 --- a/src/util/Symbol_dispose.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {root} from './root'; - -if (!root.Symbol) { - root.Symbol = {}; -} - -if (!root.Symbol.dispose) { - if (typeof root.Symbol.for === 'function') { - root.Symbol.dispose = root.Symbol.for('dispose'); - } else { - root.Symbol.dispose = '@@dispose'; - } -} - -export const $$dispose = root.Symbol.dispose; \ No newline at end of file diff --git a/src/util/Symbol_observable.ts b/src/util/Symbol_observable.ts deleted file mode 100644 index 533add7c71..0000000000 --- a/src/util/Symbol_observable.ts +++ /dev/null @@ -1,15 +0,0 @@ -import {root} from './root'; - -if (!root.Symbol) { - root.Symbol = {}; -} - -if (!root.Symbol.observable) { - if (typeof root.Symbol.for === 'function') { - root.Symbol.observable = root.Symbol.for('observable'); - } else { - root.Symbol.observable = '@@observable'; - } -} - -export const $$observable = root.Symbol.observable; \ No newline at end of file diff --git a/src/util/subscribeToResult.ts b/src/util/subscribeToResult.ts index a3dc5d8366..690d514026 100644 --- a/src/util/subscribeToResult.ts +++ b/src/util/subscribeToResult.ts @@ -1,7 +1,6 @@ import {Subscriber} from '../Subscriber'; import {Observable} from '../Observable'; -import {$$iterator} from '../util/Symbol_iterator'; -import {$$observable} from '../util/Symbol_observable'; +import {SymbolShim} from '../util/SymbolShim'; import {Subscription} from '../Subscription'; import {InnerSubscriber} from '../InnerSubscriber'; import {OuterSubscriber} from '../OuterSubscriber'; @@ -47,7 +46,7 @@ export function subscribeToResult(outerSubscriber: OuterSubscriber, setTimeout(() => { throw err; }); }); return destination; - } else if (typeof result[$$iterator] === 'function') { + } else if (typeof result[SymbolShim.iterator] === 'function') { for (let item of result) { destination.next(item); if (destination.isUnsubscribed) { @@ -57,8 +56,8 @@ export function subscribeToResult(outerSubscriber: OuterSubscriber, if (!destination.isUnsubscribed) { destination.complete(); } - } else if (typeof result[$$observable] === 'function') { - const obs = result[$$observable](); + } else if (typeof result[SymbolShim.observable] === 'function') { + const obs = result[SymbolShim.observable](); if (typeof obs.subscribe !== 'function') { destination.error('invalid observable'); } else {