Skip to content

Conversation

@phewphewb
Copy link

@phewphewb phewphewb commented Jul 3, 2022

This PR aims to improve code readability. No strong feelings attached. Feel free to close the PR if you think this is not necessary.

Copy link
Author

@phewphewb phewphewb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
export default async (options = [{}]) => {
if (!Array.isArray(options)) {
options = [options];

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

Copy link
Member

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?

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];

Copy link
Member

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.

const types = [];
options.forEach((option, i) => {
types[i] = {
const types = options.map((option) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Map looks much better here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this looks more “intended” indeed.

types[i] = {
const types = options.map((option) => {
const type = {
description: option.description || 'Files',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to use destructuring assignment for options and move const type to the end of this arrow function

}
} else {
types[i].accept['*/*'] = option.extensions || [];
type.accept['*/*'] = option.extensions || [];

Choose a reason for hiding this comment

The 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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we can use destructuring assignment for arrays and put options[0] to intermediate variable: const [first] = options; or even const [{ id, startIn, multiple, excludeAcceptAllOption }] = options;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this can work.

@tomayac
Copy link
Member

tomayac commented Jul 4, 2022

Please move on with the suggested improvements and let me know when you have agreed on a design. Thanks for the PR and discussion so far already.

@phewphewb phewphewb requested a review from tomayac July 6, 2022 01:58
@phewphewb phewphewb changed the title refactor types mapping code refactoring Jul 6, 2022
@phewphewb
Copy link
Author

phewphewb commented Jul 6, 2022

@tomayac, @tshemsedinov, I am working on updating this file if this one is fine

@tomayac
Copy link
Member

tomayac commented Jul 6, 2022

@tomayac, @tshemsedinov, I working on updating this file if this one is fine

Thanks, please do. We can turn this into a big refactoring PR.

@phewphewb
Copy link
Author

@tshemsedinov

@phewphewb
Copy link
Author

phewphewb commented Jul 30, 2022

@tshemsedinov, kind reminder for your code review please

@tomayac
Copy link
Member

tomayac commented Jan 12, 2023

Is anyone still interested in this? The code as is seems to be pretty stable, so maybe we can close this?

@phewphewb
Copy link
Author

@tomayac, the refactoring is done, it just needs a proper code review. Feel free to close the PR if you do not think this code refactoring is beneficial for the library. The only purpose of this PR was to improve code readability for any possible further feature development in the library. I am willing to put more work in it if needed.

@tomayac
Copy link
Member

tomayac commented Jan 16, 2023

@tomayac, the refactoring is done, it just needs a proper code review. Feel free to close the PR if you do not think this code refactoring is beneficial for the library. The only purpose of this PR was to improve code readability for any possible further feature development in the library. I am willing to put more work in it if needed.

Sounds good to me. Before I start my review, any changes planned for directory-open.mjs?

@phewphewb
Copy link
Author

no changes planned for directory-open.mjs

@tomayac
Copy link
Member

tomayac commented Apr 24, 2025

Closing as per #119 (comment).

@tomayac tomayac closed this Apr 24, 2025
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

Successfully merging this pull request may close these issues.

3 participants