Skip to content

Commit

Permalink
Remove Symbol.observable polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
zenparsing committed Nov 28, 2022
1 parent acb9ed3 commit 69b3548
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zen-observable",
"version": "0.9.0",
"version": "0.10.0",
"repository": "zenparsing/zen-observable",
"description": "An Implementation of ES Observables",
"homepage": "https://github.com/zenparsing/zen-observable",
Expand Down
4 changes: 0 additions & 4 deletions src/Observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
const hasSymbol = name => Boolean(Symbol[name]);
const getSymbol = name => hasSymbol(name) ? Symbol[name] : '@@' + name;

if (!hasSymbol('observable') && Object.isExtensible(Symbol)) {
Symbol.observable = Symbol('observable');
}

const SymbolIterator = getSymbol('iterator');
const SymbolObservable = getSymbol('observable');
const SymbolSpecies = getSymbol('species');
Expand Down
14 changes: 11 additions & 3 deletions test/from.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ describe('from', () => {
it('wraps the input if it is not an instance of Observable', () => {
let obj = {
'constructor': Observable,
[Symbol.observable]() { return this },
[observableSymbol]() { return this },
};
assert.ok(Observable.from(obj) !== obj);
});

it('uses @@observable as the property name unless polyfilled', () => {
let obj = {
'constructor': Observable,
'@@observable'() { return this },
};
assert.ok(Observable.from(obj) !== obj);
});

it('throws if @@observable property is not a method', () => {
assert.throws(() => Observable.from({
[Symbol.observable]: 1
[observableSymbol]: 1
}));
});

Expand All @@ -62,7 +70,7 @@ describe('from', () => {
let observer;
let cleanupCalled = true;
let observable = Observable.from({
[Symbol.observable]() { return inner },
[observableSymbol]() { return inner },
});
observable.subscribe();
assert.equal(typeof observer.next, 'function');
Expand Down
3 changes: 2 additions & 1 deletion test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ beforeEach(() => {
global.Observable = Observable;
global.hostError = null;
let $extensions = Object.getOwnPropertySymbols(Observable)[1];
let { hostReportError } = Observable[$extensions];
let { hostReportError, symbol } = Observable[$extensions];
hostReportError.log = (e => global.hostError = e);
global.observableSymbol = symbol;
});

0 comments on commit 69b3548

Please sign in to comment.