Last change
on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | export default function symbolObservablePonyfill(root) {
|
---|
2 | var result;
|
---|
3 | var Symbol = root.Symbol;
|
---|
4 |
|
---|
5 | if (typeof Symbol === 'function') {
|
---|
6 | if (Symbol.observable) {
|
---|
7 | result = Symbol.observable;
|
---|
8 | } else {
|
---|
9 |
|
---|
10 | if (typeof Symbol.for === 'function') {
|
---|
11 | // This just needs to be something that won't trample other user's Symbol.for use
|
---|
12 | // It also will guide people to the source of their issues, if this is problematic.
|
---|
13 | // META: It's a resource locator!
|
---|
14 | result = Symbol.for('https://github.com/benlesh/symbol-observable');
|
---|
15 | } else {
|
---|
16 | // Symbol.for didn't exist! The best we can do at this point is a totally
|
---|
17 | // unique symbol. Note that the string argument here is a descriptor, not
|
---|
18 | // an identifier. This symbol is unique.
|
---|
19 | result = Symbol('https://github.com/benlesh/symbol-observable');
|
---|
20 | }
|
---|
21 | try {
|
---|
22 | Symbol.observable = result;
|
---|
23 | } catch (err) {
|
---|
24 | // Do nothing. In some environments, users have frozen `Symbol` for security reasons,
|
---|
25 | // if it is frozen assigning to it will throw. In this case, we don't care, because
|
---|
26 | // they will need to use the returned value from the ponyfill.
|
---|
27 | }
|
---|
28 | }
|
---|
29 | } else {
|
---|
30 | result = '@@observable';
|
---|
31 | }
|
---|
32 |
|
---|
33 | return result;
|
---|
34 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.