Skip to content

refactor(loader-webpack): refactored aysnc await code to use promises#34

Open
suneelv wants to merge 2 commits intoaurelia:masterfrom
suneelv:refactor-async-to-promise
Open

refactor(loader-webpack): refactored aysnc await code to use promises#34
suneelv wants to merge 2 commits intoaurelia:masterfrom
suneelv:refactor-async-to-promise

Conversation

@suneelv
Copy link

@suneelv suneelv commented May 18, 2017

In response to aurelia/skeleton-navigation#821
FYI This didn't prevent the out of stack space error in ie11

@CLAassistant
Copy link

CLAassistant commented May 18, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@jods4 jods4 left a comment

Choose a reason for hiding this comment

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

I made a few comments.
Did you double check that all await expressions were guaranteed to be Promise?
I'm asking because it is legal to await something that may not be a Promise, in which case the code behaves like await 42 ==> await Promise.resolve(42)

if (!entry.templateIsLoaded) {
await this.templateLoader.loadTemplate(this, entry);
return this.templateLoader.loadTemplate(this, entry).then(() => {
return entry;
Copy link
Contributor

Choose a reason for hiding this comment

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

() => entry seems shorter?

loadTemplate(loader: Loader, entry: TemplateRegistryEntry) {
return loader.loadText(entry.address).then((text) => {
entry.template = DOM.createTemplateFromMarkup(text);
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing ; here

await this.hmrContext.handleViewChange(moduleId);
module.hot.accept(moduleId, () => {
return this.hmrContext.handleViewChange(moduleId).then((resource) => {
return resource;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why return resource?
.then(x => x) is a no-op, isn't it?

}
return await plugin.fetch(moduleId);
return plugin.fetch(moduleId).then((resource) => {
return resource;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as above: isn't .then(res => res) a no-op?

this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
this.modulesBeingLoaded.delete(moduleId);
return moduleExports;
// const moduleExports = await beingLoaded;
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't leave comments behind, git history is there for that.

this.modulesBeingLoaded.delete(moduleId);
return moduleExports;
// const moduleExports = await beingLoaded;
return beingLoaded.then((moduleExports) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just saying: when you've got a single argument, braces are optional (I find it more legible without).

this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
this.modulesBeingLoaded.delete(moduleId);
return moduleExports;
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing ;

}
return result;
loadText(url: string) {
return this.loadModule(url,false).then((result) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Space in url,false was lost.

return result.toString();
}
return result;
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing ;

@suneelv
Copy link
Author

suneelv commented May 18, 2017

@jods4 Thanks for the comments. I am new to this. I will update the pull request with changes.

@suneelv
Copy link
Author

suneelv commented May 18, 2017

@jods4 Yes I am always returning promises from all the old async methods. I am not really familiar with what loader-webpack is doing. So it would be better if you can just skim through it once again.

@jods4
Copy link
Contributor

jods4 commented May 18, 2017

Not requiring the async downlevel helpers from TS will make the code smaller... but sadly the stack overflow is still not fixed :(

Copy link
Contributor

@niieani niieani left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks.

@EisenbergEffect
Copy link
Contributor

@niieani Is this good to merge then?

@niieani
Copy link
Contributor

niieani commented Jul 31, 2017

@EisenbergEffect It would be good to test against the skeleton (I haven't) but otherwise looks good. Perhaps we can release tagged as beta or RC first, and if no issues show, re-release as final.

@EisenbergEffect
Copy link
Contributor

@jods4 Have we tested this? What should we do with this PR?

@jods4
Copy link
Contributor

jods4 commented Dec 10, 2017

@EisenbergEffect The runtime loader is really @niieani's work. I have reviewed the PR and it looks good, I haven't tested it, though.

@niieani
Copy link
Contributor

niieani commented Dec 12, 2017

Yes, looks good as @jods4 said, but I haven't tested either.

@EisenbergEffect
Copy link
Contributor

Has anyone tested this out yet?

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.

5 participants