Skip to content

Comments

Refactor/2116 2#2474

Draft
justinmmott wants to merge 2 commits intodteviot:ExperimentalTabModefrom
justinmmott:refactor/2116-2
Draft

Refactor/2116 2#2474
justinmmott wants to merge 2 commits intodteviot:ExperimentalTabModefrom
justinmmott:refactor/2116-2

Conversation

@justinmmott
Copy link
Contributor

Change the rest of the .then()s to async-await.

Ran the tests on the first commit, where there are no changes to the test files, and got all the tests to pass.

It's late, and I haven't given the code a once-over for style mistakes, so leaving this as a draft for now.

await addCssFileToZip(zip, "autoDark.css");
let fileList = await getFileList("../plugin/popup.html");
let localeNames = await getLocaleFilesNames();
["js/ContentScript.js"].concat(localeNames).concat(fileList.filter(n => !n.includes("/experimental/")));
Copy link
Owner

Choose a reason for hiding this comment

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

I think this needs to be

fileList = ["js/ContentScript.js"].concat(localeNames).concat(fileList.filter(n => !n.includes("/experimental/")));

So that next line processes the correct list of files


getChapterUrls(dom, chapterUrlsUI) {
return this.getChapterUrlsFromMultipleTocPages(dom,
async getChapterUrls(dom, chapterUrlsUI) {
Copy link
Owner

Choose a reason for hiding this comment

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

Pretty sure this needs to be

        return (await this.getChapterUrlsFromMultipleTocPages(dom,
            ComrademaoParser.extractPartialChapterList,
            ComrademaoParser.getUrlsOfTocPages,
            chapterUrlsUI
        )).reverse();

let nextUrl = QinxiaoshuoParser.urlOfNextPageOfChapter(xhr.responseXML, fetchedUrls);
return QinxiaoshuoParser.fetchPagesOfChapter(finalDom, fetchedUrls, nextUrl);
});
let xhr = await HttpClient.wrapFetch(url);
Copy link
Owner

Choose a reason for hiding this comment

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

This is using recursion due to use of then. Can be re-written as simple iteration.

}.bind(this));
async responseToJson(response) {
let data = await response.text();
this.json = JSON.parse(data);
Copy link
Owner

Choose a reason for hiding this comment

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

You're not returning this

text: data.toString()
});
var readAllFiles = async function(fileList, loadedFiles) {
return await fileList.forEach(async function(fileName) {

Choose a reason for hiding this comment

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

reduce should be used here not a forEach. Return of forEach will be undefined. (if this is an array)

See this Doc on Array.prototype.forEach. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach#return_value

What could be optimized is flattening the functions. Use an await a Promise.All for each of these items,

And each promise item in an array.

After promise.all you can return the array and it will be for all fulfilled promises. But it would throw a error still if anything failed in promise.all

Choose a reason for hiding this comment

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

Regardless.

Would be good to have unit tests of this functionality to prove it's not thread blocking at the await syntax similar to original implementation and that the return is as expected

};


(async () => {

Choose a reason for hiding this comment

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

Make this a function like init() that can be called. Call it afterwards but wrap it in a process.env variable so init is not called on import/require

This would make the code much more testable by not forcing execution on evaluation.

});
}, Promise.resolve());
var addFilesToZip = async function(zip, fileList) {
return await fileList.forEach(async function(fileName) {

Choose a reason for hiding this comment

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

Same undefined bug as above.

Choose a reason for hiding this comment

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

Add tests for inputs/outputs please!

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