collection-progressing-status.js 788 B

1234567891011121314151617181920212223242526272829303132333435
  1. const CollectionProgress = require('./collection-progress');
  2. class CollectionProgressingStatus {
  3. constructor(collections) {
  4. this.totalCount = 0;
  5. this.progressMap = {};
  6. this.progressList = collections.map((collectionName) => {
  7. return new CollectionProgress(collectionName, 0);
  8. });
  9. // collection name to instance mapping
  10. this.progressList.forEach((p) => {
  11. this.progressMap[p.collectionName] = p;
  12. });
  13. }
  14. recalculateTotalCount() {
  15. this.progressList.forEach((p) => {
  16. this.progressMap[p.collectionName] = p;
  17. this.totalCount += p.totalCount;
  18. });
  19. }
  20. get currentCount() {
  21. return this.progressList.reduce(
  22. (acc, crr) => acc + crr.currentCount,
  23. 0,
  24. );
  25. }
  26. }
  27. module.exports = CollectionProgressingStatus;