-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Symbol.observable): is no longer polyfilled
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
Showing
9 changed files
with
39 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,27 @@ | ||
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'; | ||
/** 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; | ||
} | ||
|
||
return $$observable; | ||
} | ||
|
||
export const observable = getSymbolObservable(root); | ||
/* NOTE: Warning users that they don't have a Symbol.observable | ||
polyfill. It's not something we'd throw on, because it's not | ||
really *required*, however, they should be warned to give them a | ||
clue as to why they might be seeing errors when trying to convert | ||
ObservableLikes to Observables */ | ||
if (!Symbol || !Symbol.observable) { | ||
console.warn('RxJS: Symbol.observable does not exist'); | ||
} | ||
|
||
/** | ||
* @deprecated use observable instead | ||
* @deprecated use {@link observable} | ||
*/ | ||
export const $$observable = observable; | ||
export const $$observable = Symbol && Symbol.observable || '@@observable'; | ||
|
||
declare global { | ||
interface SymbolConstructor { | ||
observable: symbol; | ||
} | ||
} | ||
/** Symbol.observable or a string "@@observable". Used for interop */ | ||
export const observable = $$observable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters