UI for Zipcoin Blue

HotModuleReplacement.runtime.js 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. /*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
  6. module.exports = function() {
  7. var hotApplyOnUpdate = true;
  8. var hotCurrentHash = $hash$; // eslint-disable-line no-unused-vars
  9. var hotRequestTimeout = $requestTimeout$;
  10. var hotCurrentModuleData = {};
  11. var hotCurrentChildModule; // eslint-disable-line no-unused-vars
  12. var hotCurrentParents = []; // eslint-disable-line no-unused-vars
  13. var hotCurrentParentsTemp = []; // eslint-disable-line no-unused-vars
  14. function hotCreateRequire(moduleId) { // eslint-disable-line no-unused-vars
  15. var me = installedModules[moduleId];
  16. if(!me) return $require$;
  17. var fn = function(request) {
  18. if(me.hot.active) {
  19. if(installedModules[request]) {
  20. if(installedModules[request].parents.indexOf(moduleId) < 0)
  21. installedModules[request].parents.push(moduleId);
  22. } else {
  23. hotCurrentParents = [moduleId];
  24. hotCurrentChildModule = request;
  25. }
  26. if(me.children.indexOf(request) < 0)
  27. me.children.push(request);
  28. } else {
  29. console.warn("[HMR] unexpected require(" + request + ") from disposed module " + moduleId);
  30. hotCurrentParents = [];
  31. }
  32. return $require$(request);
  33. };
  34. var ObjectFactory = function ObjectFactory(name) {
  35. return {
  36. configurable: true,
  37. enumerable: true,
  38. get: function() {
  39. return $require$[name];
  40. },
  41. set: function(value) {
  42. $require$[name] = value;
  43. }
  44. };
  45. };
  46. for(var name in $require$) {
  47. if(Object.prototype.hasOwnProperty.call($require$, name) && name !== "e") {
  48. Object.defineProperty(fn, name, ObjectFactory(name));
  49. }
  50. }
  51. fn.e = function(chunkId) {
  52. if(hotStatus === "ready")
  53. hotSetStatus("prepare");
  54. hotChunksLoading++;
  55. return $require$.e(chunkId).then(finishChunkLoading, function(err) {
  56. finishChunkLoading();
  57. throw err;
  58. });
  59. function finishChunkLoading() {
  60. hotChunksLoading--;
  61. if(hotStatus === "prepare") {
  62. if(!hotWaitingFilesMap[chunkId]) {
  63. hotEnsureUpdateChunk(chunkId);
  64. }
  65. if(hotChunksLoading === 0 && hotWaitingFiles === 0) {
  66. hotUpdateDownloaded();
  67. }
  68. }
  69. }
  70. };
  71. return fn;
  72. }
  73. function hotCreateModule(moduleId) { // eslint-disable-line no-unused-vars
  74. var hot = {
  75. // private stuff
  76. _acceptedDependencies: {},
  77. _declinedDependencies: {},
  78. _selfAccepted: false,
  79. _selfDeclined: false,
  80. _disposeHandlers: [],
  81. _main: hotCurrentChildModule !== moduleId,
  82. // Module API
  83. active: true,
  84. accept: function(dep, callback) {
  85. if(typeof dep === "undefined")
  86. hot._selfAccepted = true;
  87. else if(typeof dep === "function")
  88. hot._selfAccepted = dep;
  89. else if(typeof dep === "object")
  90. for(var i = 0; i < dep.length; i++)
  91. hot._acceptedDependencies[dep[i]] = callback || function() {};
  92. else
  93. hot._acceptedDependencies[dep] = callback || function() {};
  94. },
  95. decline: function(dep) {
  96. if(typeof dep === "undefined")
  97. hot._selfDeclined = true;
  98. else if(typeof dep === "object")
  99. for(var i = 0; i < dep.length; i++)
  100. hot._declinedDependencies[dep[i]] = true;
  101. else
  102. hot._declinedDependencies[dep] = true;
  103. },
  104. dispose: function(callback) {
  105. hot._disposeHandlers.push(callback);
  106. },
  107. addDisposeHandler: function(callback) {
  108. hot._disposeHandlers.push(callback);
  109. },
  110. removeDisposeHandler: function(callback) {
  111. var idx = hot._disposeHandlers.indexOf(callback);
  112. if(idx >= 0) hot._disposeHandlers.splice(idx, 1);
  113. },
  114. // Management API
  115. check: hotCheck,
  116. apply: hotApply,
  117. status: function(l) {
  118. if(!l) return hotStatus;
  119. hotStatusHandlers.push(l);
  120. },
  121. addStatusHandler: function(l) {
  122. hotStatusHandlers.push(l);
  123. },
  124. removeStatusHandler: function(l) {
  125. var idx = hotStatusHandlers.indexOf(l);
  126. if(idx >= 0) hotStatusHandlers.splice(idx, 1);
  127. },
  128. //inherit from previous dispose call
  129. data: hotCurrentModuleData[moduleId]
  130. };
  131. hotCurrentChildModule = undefined;
  132. return hot;
  133. }
  134. var hotStatusHandlers = [];
  135. var hotStatus = "idle";
  136. function hotSetStatus(newStatus) {
  137. hotStatus = newStatus;
  138. for(var i = 0; i < hotStatusHandlers.length; i++)
  139. hotStatusHandlers[i].call(null, newStatus);
  140. }
  141. // while downloading
  142. var hotWaitingFiles = 0;
  143. var hotChunksLoading = 0;
  144. var hotWaitingFilesMap = {};
  145. var hotRequestedFilesMap = {};
  146. var hotAvailableFilesMap = {};
  147. var hotDeferred;
  148. // The update info
  149. var hotUpdate, hotUpdateNewHash;
  150. function toModuleId(id) {
  151. var isNumber = (+id) + "" === id;
  152. return isNumber ? +id : id;
  153. }
  154. function hotCheck(apply) {
  155. if(hotStatus !== "idle") throw new Error("check() is only allowed in idle status");
  156. hotApplyOnUpdate = apply;
  157. hotSetStatus("check");
  158. return hotDownloadManifest(hotRequestTimeout).then(function(update) {
  159. if(!update) {
  160. hotSetStatus("idle");
  161. return null;
  162. }
  163. hotRequestedFilesMap = {};
  164. hotWaitingFilesMap = {};
  165. hotAvailableFilesMap = update.c;
  166. hotUpdateNewHash = update.h;
  167. hotSetStatus("prepare");
  168. var promise = new Promise(function(resolve, reject) {
  169. hotDeferred = {
  170. resolve: resolve,
  171. reject: reject
  172. };
  173. });
  174. hotUpdate = {};
  175. /*foreachInstalledChunks*/
  176. { // eslint-disable-line no-lone-blocks
  177. /*globals chunkId */
  178. hotEnsureUpdateChunk(chunkId);
  179. }
  180. if(hotStatus === "prepare" && hotChunksLoading === 0 && hotWaitingFiles === 0) {
  181. hotUpdateDownloaded();
  182. }
  183. return promise;
  184. });
  185. }
  186. function hotAddUpdateChunk(chunkId, moreModules) { // eslint-disable-line no-unused-vars
  187. if(!hotAvailableFilesMap[chunkId] || !hotRequestedFilesMap[chunkId])
  188. return;
  189. hotRequestedFilesMap[chunkId] = false;
  190. for(var moduleId in moreModules) {
  191. if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
  192. hotUpdate[moduleId] = moreModules[moduleId];
  193. }
  194. }
  195. if(--hotWaitingFiles === 0 && hotChunksLoading === 0) {
  196. hotUpdateDownloaded();
  197. }
  198. }
  199. function hotEnsureUpdateChunk(chunkId) {
  200. if(!hotAvailableFilesMap[chunkId]) {
  201. hotWaitingFilesMap[chunkId] = true;
  202. } else {
  203. hotRequestedFilesMap[chunkId] = true;
  204. hotWaitingFiles++;
  205. hotDownloadUpdateChunk(chunkId);
  206. }
  207. }
  208. function hotUpdateDownloaded() {
  209. hotSetStatus("ready");
  210. var deferred = hotDeferred;
  211. hotDeferred = null;
  212. if(!deferred) return;
  213. if(hotApplyOnUpdate) {
  214. // Wrap deferred object in Promise to mark it as a well-handled Promise to
  215. // avoid triggering uncaught exception warning in Chrome.
  216. // See https://bugs.chromium.org/p/chromium/issues/detail?id=465666
  217. Promise.resolve().then(function() {
  218. return hotApply(hotApplyOnUpdate);
  219. }).then(
  220. function(result) {
  221. deferred.resolve(result);
  222. },
  223. function(err) {
  224. deferred.reject(err);
  225. }
  226. );
  227. } else {
  228. var outdatedModules = [];
  229. for(var id in hotUpdate) {
  230. if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
  231. outdatedModules.push(toModuleId(id));
  232. }
  233. }
  234. deferred.resolve(outdatedModules);
  235. }
  236. }
  237. function hotApply(options) {
  238. if(hotStatus !== "ready") throw new Error("apply() is only allowed in ready status");
  239. options = options || {};
  240. var cb;
  241. var i;
  242. var j;
  243. var module;
  244. var moduleId;
  245. function getAffectedStuff(updateModuleId) {
  246. var outdatedModules = [updateModuleId];
  247. var outdatedDependencies = {};
  248. var queue = outdatedModules.slice().map(function(id) {
  249. return {
  250. chain: [id],
  251. id: id
  252. };
  253. });
  254. while(queue.length > 0) {
  255. var queueItem = queue.pop();
  256. var moduleId = queueItem.id;
  257. var chain = queueItem.chain;
  258. module = installedModules[moduleId];
  259. if(!module || module.hot._selfAccepted)
  260. continue;
  261. if(module.hot._selfDeclined) {
  262. return {
  263. type: "self-declined",
  264. chain: chain,
  265. moduleId: moduleId
  266. };
  267. }
  268. if(module.hot._main) {
  269. return {
  270. type: "unaccepted",
  271. chain: chain,
  272. moduleId: moduleId
  273. };
  274. }
  275. for(var i = 0; i < module.parents.length; i++) {
  276. var parentId = module.parents[i];
  277. var parent = installedModules[parentId];
  278. if(!parent) continue;
  279. if(parent.hot._declinedDependencies[moduleId]) {
  280. return {
  281. type: "declined",
  282. chain: chain.concat([parentId]),
  283. moduleId: moduleId,
  284. parentId: parentId
  285. };
  286. }
  287. if(outdatedModules.indexOf(parentId) >= 0) continue;
  288. if(parent.hot._acceptedDependencies[moduleId]) {
  289. if(!outdatedDependencies[parentId])
  290. outdatedDependencies[parentId] = [];
  291. addAllToSet(outdatedDependencies[parentId], [moduleId]);
  292. continue;
  293. }
  294. delete outdatedDependencies[parentId];
  295. outdatedModules.push(parentId);
  296. queue.push({
  297. chain: chain.concat([parentId]),
  298. id: parentId
  299. });
  300. }
  301. }
  302. return {
  303. type: "accepted",
  304. moduleId: updateModuleId,
  305. outdatedModules: outdatedModules,
  306. outdatedDependencies: outdatedDependencies
  307. };
  308. }
  309. function addAllToSet(a, b) {
  310. for(var i = 0; i < b.length; i++) {
  311. var item = b[i];
  312. if(a.indexOf(item) < 0)
  313. a.push(item);
  314. }
  315. }
  316. // at begin all updates modules are outdated
  317. // the "outdated" status can propagate to parents if they don't accept the children
  318. var outdatedDependencies = {};
  319. var outdatedModules = [];
  320. var appliedUpdate = {};
  321. var warnUnexpectedRequire = function warnUnexpectedRequire() {
  322. console.warn("[HMR] unexpected require(" + result.moduleId + ") to disposed module");
  323. };
  324. for(var id in hotUpdate) {
  325. if(Object.prototype.hasOwnProperty.call(hotUpdate, id)) {
  326. moduleId = toModuleId(id);
  327. var result;
  328. if(hotUpdate[id]) {
  329. result = getAffectedStuff(moduleId);
  330. } else {
  331. result = {
  332. type: "disposed",
  333. moduleId: id
  334. };
  335. }
  336. var abortError = false;
  337. var doApply = false;
  338. var doDispose = false;
  339. var chainInfo = "";
  340. if(result.chain) {
  341. chainInfo = "\nUpdate propagation: " + result.chain.join(" -> ");
  342. }
  343. switch(result.type) {
  344. case "self-declined":
  345. if(options.onDeclined)
  346. options.onDeclined(result);
  347. if(!options.ignoreDeclined)
  348. abortError = new Error("Aborted because of self decline: " + result.moduleId + chainInfo);
  349. break;
  350. case "declined":
  351. if(options.onDeclined)
  352. options.onDeclined(result);
  353. if(!options.ignoreDeclined)
  354. abortError = new Error("Aborted because of declined dependency: " + result.moduleId + " in " + result.parentId + chainInfo);
  355. break;
  356. case "unaccepted":
  357. if(options.onUnaccepted)
  358. options.onUnaccepted(result);
  359. if(!options.ignoreUnaccepted)
  360. abortError = new Error("Aborted because " + moduleId + " is not accepted" + chainInfo);
  361. break;
  362. case "accepted":
  363. if(options.onAccepted)
  364. options.onAccepted(result);
  365. doApply = true;
  366. break;
  367. case "disposed":
  368. if(options.onDisposed)
  369. options.onDisposed(result);
  370. doDispose = true;
  371. break;
  372. default:
  373. throw new Error("Unexception type " + result.type);
  374. }
  375. if(abortError) {
  376. hotSetStatus("abort");
  377. return Promise.reject(abortError);
  378. }
  379. if(doApply) {
  380. appliedUpdate[moduleId] = hotUpdate[moduleId];
  381. addAllToSet(outdatedModules, result.outdatedModules);
  382. for(moduleId in result.outdatedDependencies) {
  383. if(Object.prototype.hasOwnProperty.call(result.outdatedDependencies, moduleId)) {
  384. if(!outdatedDependencies[moduleId])
  385. outdatedDependencies[moduleId] = [];
  386. addAllToSet(outdatedDependencies[moduleId], result.outdatedDependencies[moduleId]);
  387. }
  388. }
  389. }
  390. if(doDispose) {
  391. addAllToSet(outdatedModules, [result.moduleId]);
  392. appliedUpdate[moduleId] = warnUnexpectedRequire;
  393. }
  394. }
  395. }
  396. // Store self accepted outdated modules to require them later by the module system
  397. var outdatedSelfAcceptedModules = [];
  398. for(i = 0; i < outdatedModules.length; i++) {
  399. moduleId = outdatedModules[i];
  400. if(installedModules[moduleId] && installedModules[moduleId].hot._selfAccepted)
  401. outdatedSelfAcceptedModules.push({
  402. module: moduleId,
  403. errorHandler: installedModules[moduleId].hot._selfAccepted
  404. });
  405. }
  406. // Now in "dispose" phase
  407. hotSetStatus("dispose");
  408. Object.keys(hotAvailableFilesMap).forEach(function(chunkId) {
  409. if(hotAvailableFilesMap[chunkId] === false) {
  410. hotDisposeChunk(chunkId);
  411. }
  412. });
  413. var idx;
  414. var queue = outdatedModules.slice();
  415. while(queue.length > 0) {
  416. moduleId = queue.pop();
  417. module = installedModules[moduleId];
  418. if(!module) continue;
  419. var data = {};
  420. // Call dispose handlers
  421. var disposeHandlers = module.hot._disposeHandlers;
  422. for(j = 0; j < disposeHandlers.length; j++) {
  423. cb = disposeHandlers[j];
  424. cb(data);
  425. }
  426. hotCurrentModuleData[moduleId] = data;
  427. // disable module (this disables requires from this module)
  428. module.hot.active = false;
  429. // remove module from cache
  430. delete installedModules[moduleId];
  431. // when disposing there is no need to call dispose handler
  432. delete outdatedDependencies[moduleId];
  433. // remove "parents" references from all children
  434. for(j = 0; j < module.children.length; j++) {
  435. var child = installedModules[module.children[j]];
  436. if(!child) continue;
  437. idx = child.parents.indexOf(moduleId);
  438. if(idx >= 0) {
  439. child.parents.splice(idx, 1);
  440. }
  441. }
  442. }
  443. // remove outdated dependency from module children
  444. var dependency;
  445. var moduleOutdatedDependencies;
  446. for(moduleId in outdatedDependencies) {
  447. if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
  448. module = installedModules[moduleId];
  449. if(module) {
  450. moduleOutdatedDependencies = outdatedDependencies[moduleId];
  451. for(j = 0; j < moduleOutdatedDependencies.length; j++) {
  452. dependency = moduleOutdatedDependencies[j];
  453. idx = module.children.indexOf(dependency);
  454. if(idx >= 0) module.children.splice(idx, 1);
  455. }
  456. }
  457. }
  458. }
  459. // Not in "apply" phase
  460. hotSetStatus("apply");
  461. hotCurrentHash = hotUpdateNewHash;
  462. // insert new code
  463. for(moduleId in appliedUpdate) {
  464. if(Object.prototype.hasOwnProperty.call(appliedUpdate, moduleId)) {
  465. modules[moduleId] = appliedUpdate[moduleId];
  466. }
  467. }
  468. // call accept handlers
  469. var error = null;
  470. for(moduleId in outdatedDependencies) {
  471. if(Object.prototype.hasOwnProperty.call(outdatedDependencies, moduleId)) {
  472. module = installedModules[moduleId];
  473. if(module) {
  474. moduleOutdatedDependencies = outdatedDependencies[moduleId];
  475. var callbacks = [];
  476. for(i = 0; i < moduleOutdatedDependencies.length; i++) {
  477. dependency = moduleOutdatedDependencies[i];
  478. cb = module.hot._acceptedDependencies[dependency];
  479. if(cb) {
  480. if(callbacks.indexOf(cb) >= 0) continue;
  481. callbacks.push(cb);
  482. }
  483. }
  484. for(i = 0; i < callbacks.length; i++) {
  485. cb = callbacks[i];
  486. try {
  487. cb(moduleOutdatedDependencies);
  488. } catch(err) {
  489. if(options.onErrored) {
  490. options.onErrored({
  491. type: "accept-errored",
  492. moduleId: moduleId,
  493. dependencyId: moduleOutdatedDependencies[i],
  494. error: err
  495. });
  496. }
  497. if(!options.ignoreErrored) {
  498. if(!error)
  499. error = err;
  500. }
  501. }
  502. }
  503. }
  504. }
  505. }
  506. // Load self accepted modules
  507. for(i = 0; i < outdatedSelfAcceptedModules.length; i++) {
  508. var item = outdatedSelfAcceptedModules[i];
  509. moduleId = item.module;
  510. hotCurrentParents = [moduleId];
  511. try {
  512. $require$(moduleId);
  513. } catch(err) {
  514. if(typeof item.errorHandler === "function") {
  515. try {
  516. item.errorHandler(err);
  517. } catch(err2) {
  518. if(options.onErrored) {
  519. options.onErrored({
  520. type: "self-accept-error-handler-errored",
  521. moduleId: moduleId,
  522. error: err2,
  523. orginalError: err, // TODO remove in webpack 4
  524. originalError: err
  525. });
  526. }
  527. if(!options.ignoreErrored) {
  528. if(!error)
  529. error = err2;
  530. }
  531. if(!error)
  532. error = err;
  533. }
  534. } else {
  535. if(options.onErrored) {
  536. options.onErrored({
  537. type: "self-accept-errored",
  538. moduleId: moduleId,
  539. error: err
  540. });
  541. }
  542. if(!options.ignoreErrored) {
  543. if(!error)
  544. error = err;
  545. }
  546. }
  547. }
  548. }
  549. // handle errors in accept handlers and self accepted module load
  550. if(error) {
  551. hotSetStatus("fail");
  552. return Promise.reject(error);
  553. }
  554. hotSetStatus("idle");
  555. return new Promise(function(resolve) {
  556. resolve(outdatedModules);
  557. });
  558. }
  559. };