UI for Zipcoin Blue

signal.js 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 log = require("./log");
  8. var checkForUpdate = function checkForUpdate(fromUpdate) {
  9. module.hot.check().then(function(updatedModules) {
  10. if(!updatedModules) {
  11. if(fromUpdate)
  12. log("info", "[HMR] Update applied.");
  13. else
  14. log("warning", "[HMR] Cannot find update.");
  15. return;
  16. }
  17. return module.hot.apply({
  18. ignoreUnaccepted: true,
  19. onUnaccepted: function(data) {
  20. log("warning", "Ignored an update to unaccepted module " + data.chain.join(" -> "));
  21. },
  22. }).then(function(renewedModules) {
  23. require("./log-apply-result")(updatedModules, renewedModules);
  24. checkForUpdate(true);
  25. });
  26. }).catch(function(err) {
  27. var status = module.hot.status();
  28. if(["abort", "fail"].indexOf(status) >= 0) {
  29. log("warning", "[HMR] Cannot apply update.");
  30. log("warning", "[HMR] " + err.stack || err.message);
  31. log("warning", "[HMR] You need to restart the application!");
  32. } else {
  33. log("warning", "[HMR] Update failed: " + err.stack || err.message);
  34. }
  35. });
  36. };
  37. process.on(__resourceQuery.substr(1) || "SIGUSR2", function() {
  38. if(module.hot.status() !== "idle") {
  39. log("warning", "[HMR] Got signal but currently in " + module.hot.status() + " state.");
  40. log("warning", "[HMR] Need to be in idle state to start hot update.");
  41. return;
  42. }
  43. checkForUpdate();
  44. });
  45. } else {
  46. throw new Error("[HMR] Hot Module Replacement is disabled.");
  47. }