Skip to content

Commit

Permalink
feat: directive instance options
Browse files Browse the repository at this point in the history
resolve #41
  • Loading branch information
kukhariev committed May 23, 2019
1 parent 125ae31 commit 9cb7665
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/uploadx/src/uploadx.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class UploadxDirective implements OnInit, OnDestroy {
this.uploadx.allowedTypes
);
}
this.uploadService.init(this.uploadx);
}
this.uploadxState.emit(this.uploadService.events);
this.listenerFn = this.renderer.listen(
Expand All @@ -59,7 +58,7 @@ export class UploadxDirective implements OnInit, OnDestroy {

fileListener = () => {
if (this.elementRef.nativeElement.files) {
this.uploadService.handleFileList(this.elementRef.nativeElement.files);
this.uploadService.handleFileList(this.elementRef.nativeElement.files, this.uploadx);
}
};
}
16 changes: 9 additions & 7 deletions src/uploadx/src/uploadx.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class UploadxService {
*/
init(options: UploadxOptions): Observable<UploadState> {
this.options = { ...this.options, ...options };
this.uploaderClass = this.options.uploaderClass;
return this.events;
}
/**
Expand All @@ -71,21 +70,24 @@ export class UploadxService {
/**
* Create Uploader and add to the queue
*/
handleFileList(fileList: FileList): void {
Array.from(fileList).forEach(file => this.addUploaderInstance(file));
handleFileList(fileList: FileList, options = {}): void {
const instanceOptions = { ...this.options, ...options };
Array.from(fileList).forEach(file => this.addUploaderInstance(file, instanceOptions));
this.autoUploadFiles();
}

/**
* Create Uploader for the file and add to the queue
*/
handleFile(file: File): void {
this.addUploaderInstance(file);
handleFile(file: File, options = {}): void {
const instanceOptions = { ...this.options, ...options };
this.addUploaderInstance(file, instanceOptions);
this.autoUploadFiles();
}

private addUploaderInstance(file: File) {
const uploader = new this.uploaderClass(file, this.options as UploaderOptions);
private addUploaderInstance(file: File, options) {
this.uploaderClass = options.uploaderClass;
const uploader = new this.uploaderClass(file, options);
this.queue.push(uploader);
uploader.status = 'added';
}
Expand Down

0 comments on commit 9cb7665

Please sign in to comment.