AsyncDependenciesBlock.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const DependenciesBlock = require("./DependenciesBlock");
  7. module.exports = class AsyncDependenciesBlock extends DependenciesBlock {
  8. constructor(name, module, loc) {
  9. super();
  10. this.chunkName = name;
  11. this.chunks = null;
  12. this.module = module;
  13. this.loc = loc;
  14. }
  15. get chunk() {
  16. throw new Error("`chunk` was been renamed to `chunks` and is now an array");
  17. }
  18. set chunk(chunk) {
  19. throw new Error("`chunk` was been renamed to `chunks` and is now an array");
  20. }
  21. updateHash(hash) {
  22. hash.update(this.chunkName || "");
  23. hash.update(this.chunks && this.chunks.map((chunk) => {
  24. return chunk.id !== null ? chunk.id : "";
  25. }).join(",") || "");
  26. super.updateHash(hash);
  27. }
  28. disconnect() {
  29. this.chunks = null;
  30. super.disconnect();
  31. }
  32. unseal() {
  33. this.chunks = null;
  34. super.unseal();
  35. }
  36. sortItems() {
  37. super.sortItems();
  38. if(this.chunks) {
  39. this.chunks.sort((a, b) => {
  40. let i = 0;
  41. while(true) { // eslint-disable-line no-constant-condition
  42. if(!a.modules[i] && !b.modules[i]) return 0;
  43. if(!a.modules[i]) return -1;
  44. if(!b.modules[i]) return 1;
  45. if(a.modules[i].id > b.modules[i].id) return 1;
  46. if(a.modules[i].id < b.modules[i].id) return -1;
  47. i++;
  48. }
  49. });
  50. }
  51. }
  52. };