Module.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Node from './Node';
  2. export default class Module extends Node {
  3. constructor(name, data, parent) {
  4. super(name, parent);
  5. this.data = data;
  6. }
  7. get src() {
  8. return this.data.parsedSrc;
  9. }
  10. set src(value) {
  11. this.data.parsedSrc = value;
  12. delete this._gzipSize;
  13. }
  14. get size() {
  15. return this.data.size;
  16. }
  17. set size(value) {
  18. this.data.size = value;
  19. }
  20. get parsedSize() {
  21. return this.getParsedSize();
  22. }
  23. get gzipSize() {
  24. return this.getGzipSize();
  25. }
  26. getParsedSize() {
  27. return this.src ? this.src.length : undefined;
  28. }
  29. getGzipSize() {
  30. if (!('_gzipSize' in this)) {
  31. this._gzipSize = this.src ? 999999 : undefined; // TODO - fix this
  32. }
  33. return this._gzipSize;
  34. }
  35. mergeData(data) {
  36. if (data.size) {
  37. this.size += data.size;
  38. }
  39. if (data.parsedSrc) {
  40. this.src = (this.src || '') + data.parsedSrc;
  41. }
  42. }
  43. toChartData() {
  44. return {
  45. id: this.data.id,
  46. label: this.name,
  47. path: this.path,
  48. statSize: this.size,
  49. parsedSize: this.parsedSize,
  50. gzipSize: this.gzipSize,
  51. };
  52. }
  53. }