Skip to content

Commit

Permalink
feat(Symbol.observable): is no longer polyfilled (#3387)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: RxJS will no longer be polyfilling Symbol.observable. That should be done by an actual polyfill library. This is to prevent duplication of code, and also to prevent having modules with side-effects in rxjs.
  • Loading branch information
benlesh authored Mar 8, 2018
1 parent 3e4772e commit 4a5aaaf
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 56 deletions.
11 changes: 11 additions & 0 deletions spec/helpers/polyfills.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if (typeof Symbol !== 'function') {
let id = 0;
const symbolFn: any = (description: string) =>
`Symbol_${id++} ${description} (RxJS Testing Polyfill)`;

Symbol = symbolFn;
}

if (!(Symbol as any).observable) {
(Symbol as any).observable = Symbol('Symbol.observable polyfill from RxJS Testing');
}
3 changes: 2 additions & 1 deletion spec/support/coverage.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--require spec/helpers/polyfills.ts
--require spec/helpers/testScheduler-ui.ts
--ui spec/helpers/testScheduler-ui.ts

Expand All @@ -6,4 +7,4 @@
--globals WebSocket,FormData,XDomainRequest,ActiveXObject

--recursive
--timeout 5000
--timeout 5000
1 change: 1 addition & 0 deletions spec/support/default.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--require .out/spec/helpers/polyfills.ts
--require .out/spec/helpers/testScheduler-ui.js
--ui .out/spec/helpers/testScheduler-ui.js

Expand Down
3 changes: 2 additions & 1 deletion spec/support/tests2png.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--require spec-js/helpers/polyfills.ts
--require source-map-support/register
--require spec/helpers/tests2png/diagram-test-runner.ts
--require spec/helpers/testScheduler-ui.ts
Expand All @@ -6,4 +7,4 @@
--reporter dot

--recursive
--timeout 5000
--timeout 5000
5 changes: 3 additions & 2 deletions spec/support/webpack.mocha.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var path = require('path');
var glob = require('glob');
var webpack = require('webpack');

var globPattern = 'spec-js/**/!(mocha.sauce.gruntfile|mocha.sauce.runner|webpack.mocha.config|painter|diagram-test-runner|testScheduler-ui).js';
var globPattern = 'spec-js/**/!(mocha.sauce.gruntfile|mocha.sauce.runner|webpack.mocha.config|painter|diagram-test-runner|polyfills|testScheduler-ui).js';
var files = _.map(glob.sync(globPattern), function (x) {
return path.resolve('./', x);
});
Expand All @@ -18,6 +18,7 @@ module.exports = {
},

entry: {
'browser.polyfills': './spec-js/helpers/polyfills.js',
'browser.testscheduler': './spec-js/helpers/testScheduler-ui.js',
'browser.spec': files
},
Expand All @@ -31,4 +32,4 @@ module.exports = {
new webpack.optimize.CommonsChunkPlugin('browser.common.js'),
new webpack.IgnorePlugin(/^mocha$/)
]
};
};
10 changes: 0 additions & 10 deletions spec/symbol/observable-polyfilled-spec.ts

This file was deleted.

16 changes: 0 additions & 16 deletions spec/symbol/observable-spec.ts

This file was deleted.

33 changes: 7 additions & 26 deletions src/internal/symbol/observable.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
import { root } from '../util/root';

export function getSymbolObservable(context: { Symbol: SymbolConstructor; }): symbol {
let $$observable: symbol;
let Symbol = context.Symbol;

if (typeof Symbol === 'function') {
if (Symbol.observable) {
$$observable = Symbol.observable;
} else {
$$observable = Symbol('observable');
Symbol.observable = $$observable;
}
} else {
$$observable = <any>'@@observable';
}

return $$observable;
}

export const observable = getSymbolObservable(root);

/**
* @deprecated use observable instead
*/
export const $$observable = observable;

/** Symbol.observable addition */
/* Note: This will add Symbol.observable globally for all TypeScript users,
however, we are no longer polyfilling Symbol.observable */
declare global {
interface SymbolConstructor {
observable: symbol;
}
}
}

/** Symbol.observable or a string "@@observable". Used for interop */
export const observable = typeof Symbol === 'function' && Symbol.observable || '@@observable';

0 comments on commit 4a5aaaf

Please sign in to comment.