ponyfill.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports['default'] = symbolObservablePonyfill;
  6. function symbolObservablePonyfill(root) {
  7. var result;
  8. var _Symbol = root.Symbol;
  9. if (typeof _Symbol === 'function') {
  10. if (_Symbol.observable) {
  11. result = _Symbol.observable;
  12. } else {
  13. if (typeof _Symbol['for'] === 'function') {
  14. // This just needs to be something that won't trample other user's Symbol.for use
  15. // It also will guide people to the source of their issues, if this is problematic.
  16. // META: It's a resource locator!
  17. result = _Symbol['for']('https://github.com/benlesh/symbol-observable');
  18. } else {
  19. // Symbol.for didn't exist! The best we can do at this point is a totally
  20. // unique symbol. Note that the string argument here is a descriptor, not
  21. // an identifier. This symbol is unique.
  22. result = _Symbol('https://github.com/benlesh/symbol-observable');
  23. }
  24. try {
  25. _Symbol.observable = result;
  26. } catch (err) {
  27. // Do nothing. In some environments, users have frozen `Symbol` for security reasons,
  28. // if it is frozen assigning to it will throw. In this case, we don't care, because
  29. // they will need to use the returned value from the ponyfill.
  30. }
  31. }
  32. } else {
  33. result = '@@observable';
  34. }
  35. return result;
  36. };