Skip to content

Conversation

@JJ
Copy link
Contributor

@JJ JJ commented Oct 10, 2022

✍️ Description

While doing #1204 a bit of refactoring is needed; and I realized this return value is never used. Giving it its own PR since it's a change in API, and want it to be tested with the rest.

Also, some refactoring mainly eliminating await and return where they're not actually needed.

🏗️ Fixes PROD4PROD-1931

It contributes to cleaning the repository, and improve test coverage in importer; eliminating code that's not used will no doubt contribute to that.

♥️ Thank you!

Juan Julián (JJ) Merelo added 3 commits October 10, 2022 07:56
@JJ JJ changed the title [:coffin:] Result of refreshFiles is never used [:coffin:] Refactoring return values Oct 10, 2022
Copy link
Contributor

@fhd fhd left a comment

Choose a reason for hiding this comment

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

Think I found a few issues - but probably @RichardSto should also take a look.

}
for (const file of storage.files) {
resolvedFiles.push(await file);
resolvedFiles.push(file);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's called resolvedFiles, and the await is what resolves them. Are you sure this can go?

That said, a more succinct way of doing this would be:

const resolvedFiles = await Promise.all(storage.files);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case, I think I'd also change files to filePromises or something like that. It was not entirely clear from the context that was the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, stat returns a Promise<Stats>. That should have been obvious. Still, naming matters...

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess pendingFiles would work, though I personally find it obvious enough.

const handleRemoveFile = (fileID) => {
setAccount(null);
return storage.removeFile(fileID);
storage.removeFile(fileID);
Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that return value is actually being used, at least in facebookImport. I didn't check, but I'll just resume storage.removeFile is either async or explicitly returns a promise. So this function explicitly returns said promise so that it can be awaited.

A possibly more clear/modern way of writing this would be:

const handelRemoveFile = async (fileID) => {
    setAccount(null);
    await storage.removeFile(fileID);
};

JJ added a commit that referenced this pull request Oct 13, 2022
# ✍️ Description

Assigning a value to an attribute violated encapsulation, which is easy
to do in JS, but still. This is a cleaner API, with a private
`changeListener` which is assigned when the object is built.

### 🏗️ Works with PROD4POD-1931

Still cleaning up and refactoring the importer, looking at improving
coverage. Related to #1209 and #1204, but wanted it to be considered on
its own.

Also it's a change of API, which is better if considered on its own.
Juan Julián (JJ) Merelo added 2 commits October 17, 2022 08:35
@JJ JJ requested a review from RichardSto October 17, 2022 06:51
Copy link
Contributor

@fhd fhd left a comment

Choose a reason for hiding this comment

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

LGTM

@JJ JJ merged commit 34b79e5 into main Oct 18, 2022
@JJ JJ deleted the ♻-PROD4POD-1930-refreshFiles branch October 18, 2022 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants