-
Notifications
You must be signed in to change notification settings - Fork 85
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
code refactoring #119
base: main
Are you sure you want to change the base?
code refactoring #119
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,19 +29,19 @@ export default async (options = [{}]) => { | |
if (!Array.isArray(options)) { | ||
options = [options]; | ||
} | ||
const types = []; | ||
options.forEach((option, i) => { | ||
types[i] = { | ||
const types = options.map((option) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Map looks much better here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this looks more “intended” indeed. |
||
const type = { | ||
description: option.description || 'Files', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to use destructuring assignment for options and move |
||
accept: {}, | ||
}; | ||
if (option.mimeTypes) { | ||
option.mimeTypes.map((mimeType) => { | ||
types[i].accept[mimeType] = option.extensions || []; | ||
}); | ||
for (const mimeType of option.mimeTypes) { | ||
type.accept[mimeType] = option.extensions || []; | ||
} | ||
} else { | ||
types[i].accept['*/*'] = option.extensions || []; | ||
type.accept['*/*'] = option.extensions || []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code duplication, see line 39 |
||
} | ||
return type; | ||
}); | ||
const handleOrHandles = await window.showOpenFilePicker({ | ||
id: options[0].id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also we can use destructuring assignment for arrays and put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this can work. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to mutate parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you propose as an alternative if the function should accept arrays and single values at the same time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const opts = Array.isArray(options) ? options : [options];
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but what would be the advantage? Honestly curious.