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

code refactoring #119

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

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.

@@ -29,19 +29,19 @@ 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.

options.forEach((option, i) => {
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

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