Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicates in upload file list #1

Open
tp1972 opened this issue Aug 16, 2018 · 2 comments
Open

Duplicates in upload file list #1

tp1972 opened this issue Aug 16, 2018 · 2 comments

Comments

@tp1972
Copy link

tp1972 commented Aug 16, 2018

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.

@LukasMarx
Copy link
Owner

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.

@timothylombrana
Copy link

timothylombrana commented Apr 11, 2019

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); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants