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