poll.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. /*globals __resourceQuery */
  6. if(module.hot) {
  7. var hotPollInterval = +(__resourceQuery.substr(1)) || (10 * 60 * 1000);
  8. var checkForUpdate = function checkForUpdate(fromUpdate) {
  9. if(module.hot.status() === "idle") {
  10. module.hot.check(true).then(function(updatedModules) {
  11. if(!updatedModules) {
  12. if(fromUpdate) console.log("[HMR] Update applied.");
  13. return;
  14. }
  15. require("./log-apply-result")(updatedModules, updatedModules);
  16. checkForUpdate(true);
  17. }).catch(function(err) {
  18. var status = module.hot.status();
  19. if(["abort", "fail"].indexOf(status) >= 0) {
  20. console.warn("[HMR] Cannot apply update.");
  21. console.warn("[HMR] " + err.stack || err.message);
  22. console.warn("[HMR] You need to restart the application!");
  23. } else {
  24. console.warn("[HMR] Update failed: " + err.stack || err.message);
  25. }
  26. });
  27. }
  28. };
  29. setInterval(checkForUpdate, hotPollInterval);
  30. } else {
  31. throw new Error("[HMR] Hot Module Replacement is disabled.");
  32. }