Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

loadScript.native.js 920B

12345678910111213141516171819202122232425262728
  1. /**
  2. * Loads a script from a specific URL. React Native cannot load a JS
  3. * file/resource/URL via a <script> HTML element, so the implementation
  4. * fetches the specified src as plain text using fetch() and then
  5. * evaluates the fetched string as JavaScript code (i.e. via the {@link eval}
  6. * function).
  7. *
  8. * @param {string} url - The absolute URL from the which the script is to be
  9. * (down)loaded.
  10. * @returns {void}
  11. */
  12. export function loadScript(url) {
  13. return (
  14. fetch(url, { method: 'GET' })
  15. .then(response => {
  16. switch (response.status) {
  17. case 200:
  18. return response.responseText || response.text();
  19. default:
  20. throw response.statusText;
  21. }
  22. })
  23. .then(responseText => {
  24. eval.call(window, responseText); // eslint-disable-line no-eval
  25. }));
  26. }