JsonpMainTemplate.runtime.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. /*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ $crossOriginLoading$ */
  6. module.exports = function() {
  7. function webpackHotUpdateCallback(chunkId, moreModules) { // eslint-disable-line no-unused-vars
  8. hotAddUpdateChunk(chunkId, moreModules);
  9. if(parentHotUpdateCallback) parentHotUpdateCallback(chunkId, moreModules);
  10. } //$semicolon
  11. function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars
  12. var head = document.getElementsByTagName("head")[0];
  13. var script = document.createElement("script");
  14. script.type = "text/javascript";
  15. script.charset = "utf-8";
  16. script.src = $require$.p + $hotChunkFilename$;
  17. $crossOriginLoading$;
  18. head.appendChild(script);
  19. }
  20. function hotDownloadManifest(requestTimeout) { // eslint-disable-line no-unused-vars
  21. requestTimeout = requestTimeout || 10000;
  22. return new Promise(function(resolve, reject) {
  23. if(typeof XMLHttpRequest === "undefined")
  24. return reject(new Error("No browser support"));
  25. try {
  26. var request = new XMLHttpRequest();
  27. var requestPath = $require$.p + $hotMainFilename$;
  28. request.open("GET", requestPath, true);
  29. request.timeout = requestTimeout;
  30. request.send(null);
  31. } catch(err) {
  32. return reject(err);
  33. }
  34. request.onreadystatechange = function() {
  35. if(request.readyState !== 4) return;
  36. if(request.status === 0) {
  37. // timeout
  38. reject(new Error("Manifest request to " + requestPath + " timed out."));
  39. } else if(request.status === 404) {
  40. // no update available
  41. resolve();
  42. } else if(request.status !== 200 && request.status !== 304) {
  43. // other failure
  44. reject(new Error("Manifest request to " + requestPath + " failed."));
  45. } else {
  46. // success
  47. try {
  48. var update = JSON.parse(request.responseText);
  49. } catch(e) {
  50. reject(e);
  51. return;
  52. }
  53. resolve(update);
  54. }
  55. };
  56. });
  57. }
  58. };