Skip to content

Commit

Permalink
Merge pull request #53 from giautm/fix/symbol-polyfill-conflictive
Browse files Browse the repository at this point in the history
Fix(Symbol): Conflictive polyfill
  • Loading branch information
zenparsing committed Oct 19, 2018
2 parents b9b7fa7 + ffb3595 commit dc47a21
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ if (hasSymbols() && !hasSymbol('observable')) {
Symbol.observable = Symbol('observable');
}

const SymbolIterator = getSymbol('iterator');
const SymbolObservable = getSymbol('observable');
const SymbolSpecies = getSymbol('species');
// === Abstract Operations ===

function getMethod(obj, key) {
Expand All @@ -25,7 +28,7 @@ function getMethod(obj, key) {
function getSpecies(obj) {
let ctor = obj.constructor;
if (ctor !== undefined) {
ctor = ctor[getSymbol('species')];
ctor = ctor[SymbolSpecies];
if (ctor === null) {
ctor = undefined;
}
Expand Down Expand Up @@ -388,15 +391,15 @@ export class Observable {
});
}

[getSymbol('observable')]() { return this }
[SymbolObservable]() { return this }

static from(x) {
let C = typeof this === 'function' ? this : Observable;

if (x == null)
throw new TypeError(x + ' is not an object');

let method = getMethod(x, getSymbol('observable'));
let method = getMethod(x, SymbolObservable);
if (method) {
let observable = method.call(x);

Expand All @@ -410,7 +413,7 @@ export class Observable {
}

if (hasSymbol('iterator')) {
method = getMethod(x, getSymbol('iterator'));
method = getMethod(x, SymbolIterator);
if (method) {
return new C(observer => {
enqueue(() => {
Expand Down Expand Up @@ -456,14 +459,14 @@ export class Observable {
});
}

static get [getSymbol('species')]() { return this }
static get [SymbolSpecies]() { return this }

}

if (hasSymbols()) {
Object.defineProperty(Observable, Symbol('extensions'), {
value: {
symbol: getSymbol('observable'),
symbol: SymbolObservable,
hostReportError,
},
configurabe: true,
Expand Down

0 comments on commit dc47a21

Please sign in to comment.