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

Download refactor separate callback #1545

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

VilppeRiskidev
Copy link
Collaborator

No description provided.

@VilppeRiskidev VilppeRiskidev force-pushed the download-refactor-separate-callback branch from 42bb355 to 0438561 Compare November 13, 2024 11:54
this.downloadingMod = false;
}
});
await ModDownloadUtils.downloadCompletedCallback(this.profile, downloadedMods, this.$store);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's currently possible for this to throw an unhandled exception and the next line never gets executed. (Granted, it was possible earlier too.)

import ConflictManagementProvider from "../providers/generic/installing/ConflictManagementProvider";
import { installModsToProfile } from "../utils/ProfileUtils";

export async function downloadCompletedCallback(profile: Profile, downloadedMods: ThunderstoreCombo[], store: Store<any>) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • I think calling this downloadCompletedCallback is not ideal, as it semantically binds it to the call site. Ideally a utility function would be a standalone thing. E.g. after your refactorings this might not be called as a callback anymore. If you end up doing it this way, I'd think about what this function actually does and rename it to describe that.
  • Also this function also deals with stuff that happens after the download is completed, so "download utils" is not the location I would place it into
  • Showing the error modal, and thus the try-catch is IMO the UI components responsibility. One of the points of these refactorings is preparing for TCLI to implement these methods. It can't trigger a UI stuff in this manner, it has to be handled by the component.
  • Same thing sort of applies to dispatching 'profile/updateModList', but to a lesser extend, as we can assume that's something the TCLI could implement internally. Generally speaking avoiding passing the Vuex store to an util function is probably a good idea, unless there's no way to work around it.
  • We want to get rid of Profile, so a new function like this should use ImmutableProfile as argument type.
  • Due to the above, I'm not sure this method is a very good refactoring candidate. It currently already calls different utility functions so there's not that much nitty-gritty business logic in the component. However, this is a bit of grey area, so if you want to proceed with this approach, take the comments above into consideration.

import ProfileModList from '../../r2mm/mods/ProfileModList';
import Profile from '../../model/Profile';
import * as ModDownloadUtils from "../../utils/ModDownloadUtils";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick: all the other imports here use single quotes.

}, 1);
}

async downloadProgressCallback(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I had a long comment written here and now it's gone probably due to the review being in progress while the branch was force pushed. Short version: this change is good. But there are things to keep in mind for the next steps. Remember to ask me about "The Big Picture" in tomorrow's daily, as I refined the future plans a bit.

@@ -23,3 +32,58 @@ export async function downloadCompletedCallback(profile: Profile, downloadedMods
}
});
}

export async function downloadProgressCallback (
Copy link
Collaborator

Choose a reason for hiding this comment

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

Having this as a separate method in the vue component makes sense, as it removed duplicated code. However, I'm not so sure having it as a utility function is a good idea. The fact that this takes 11 arguments which mostly deal with managing the component's internal state means that it's not really a standalone in anyway. It's so tightly coupled with the current component, I'd argue that having it in a separate file actually makes the code harder to read. Also The Big Picture stuff argues against moving this here.

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.

2 participants