Open tp1972 opened 6 years ago
You are right, I didn't think that through. Set is comparing its entries references if it stores objects. These will never be equal, when adding the same file multiple times.
Unfortunately, there seems to be no way to teach the Set a way to compare objects.
To fix this issue, one would probably use an array for easy iteration and a map (POJO) with the file name as a key to check if the file is already in the array.
Here's my method for handling this. With a lil help from a lodash method.
private mergeFiles(files: File[]): Set<File> { const tempArr = _.uniqBy([...this.files].concat(files), 'name'); return new Set(tempArr); }
Hi, first: great article/tutorial about uploading files in Angular - thx.
What I noticed is that selected files are put into new Set() object and if you click on "Add files" multiple times, and add the same file, you get multiple records of the same file in the Set file object.
Isn't the purpose to use Set() object to avoid duplicates?
Thx, Bye.