Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Symbol.observable): is no longer polyfilled #3387

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-js/helpers/tests2png/diagram-test-runner.js
--require spec-js/helpers/testScheduler-ui.js
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';