var Class = require('../utils/Class'); var MultiFile = new Class({ initialize: function MultiFile(loader, type, key, files){ var finalFiles = [] ; files.forEach(function (file){ if (file) { finalFiles.push(file); } } ); this.loader = loader; this.type = type; this.key = key; this.multiKeyIndex = loader.multiKeyIndex++ ; this.files = finalFiles; this.complete = false ; this.pending = _AN_Read_length('length', finalFiles); this.failed = 0; this.config = { } ; _AN_Write_baseurl('baseURL', this, false , _AN_Read_baseurl('baseURL', loader)); this.path = loader.path; this.prefix = loader.prefix; for (var i = 0; i < (_AN_Read_length('length', finalFiles)); i++ ){ finalFiles[i].multiFile = this; } } , isReadyToProcess: function (){ return (this.pending === 0 && this.failed === 0 && !this.complete); } , addToMultiFile: function (file){ this.files.push(file); file.multiFile = this; this.pending++ ; this.complete = false ; return this; } , onFileComplete: function (file){ var index = this.files.indexOf(file); if (index !== -1) { this.pending-- ; } } , onFileFailed: function (file){ var index = this.files.indexOf(file); if (index !== -1) { this.failed++ ; } } } ); module.exports = MultiFile;