Skip to content

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

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

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

Conversation

@suneelv

@suneelv suneelv commented May 18, 2017

Copy link
Copy Markdown

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

@CLAassistant

CLAassistant commented May 18, 2017

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jods4 jods4 left a comment

Copy link
Copy Markdown
Contributor

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)

Comment thread src/aurelia-loader-webpack.ts Outdated
if (!entry.templateIsLoaded) {
await this.templateLoader.loadTemplate(this, entry);
return this.templateLoader.loadTemplate(this, entry).then(() => {
return entry;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

() => entry seems shorter?

Comment thread src/aurelia-loader-webpack.ts Outdated
loadTemplate(loader: Loader, entry: TemplateRegistryEntry) {
return loader.loadText(entry.address).then((text) => {
entry.template = DOM.createTemplateFromMarkup(text);
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing ; here

Comment thread src/aurelia-loader-webpack.ts Outdated
await this.hmrContext.handleViewChange(moduleId);
module.hot.accept(moduleId, () => {
return this.hmrContext.handleViewChange(moduleId).then((resource) => {
return resource;

Copy link
Copy Markdown
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?

Comment thread src/aurelia-loader-webpack.ts Outdated
}
return await plugin.fetch(moduleId);
return plugin.fetch(moduleId).then((resource) => {
return resource;

Copy link
Copy Markdown
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?

Comment thread src/aurelia-loader-webpack.ts Outdated
this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
this.modulesBeingLoaded.delete(moduleId);
return moduleExports;
// const moduleExports = await beingLoaded;

Copy link
Copy Markdown
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.

Comment thread src/aurelia-loader-webpack.ts Outdated
this.modulesBeingLoaded.delete(moduleId);
return moduleExports;
// const moduleExports = await beingLoaded;
return beingLoaded.then((moduleExports) => {

Copy link
Copy Markdown
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).

Comment thread src/aurelia-loader-webpack.ts Outdated
this.moduleRegistry[moduleId] = ensureOriginOnExports(moduleExports, moduleId);
this.modulesBeingLoaded.delete(moduleId);
return moduleExports;
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing ;

Comment thread src/aurelia-loader-webpack.ts Outdated
}
return result;
loadText(url: string) {
return this.loadModule(url,false).then((result) => {

Copy link
Copy Markdown
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.

Comment thread src/aurelia-loader-webpack.ts Outdated
return result.toString();
}
return result;
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing ;

@suneelv

suneelv commented May 18, 2017

Copy link
Copy Markdown
Author

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

@suneelv

suneelv commented May 18, 2017

Copy link
Copy Markdown
Author

@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

jods4 commented May 18, 2017

Copy link
Copy Markdown
Contributor

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

@niieani niieani left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@niieani Is this good to merge then?

@niieani

niieani commented Jul 31, 2017

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
Contributor

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

@jods4

jods4 commented Dec 10, 2017

Copy link
Copy Markdown
Contributor

@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

niieani commented Dec 12, 2017

Copy link
Copy Markdown
Contributor

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

@EisenbergEffect

Copy link
Copy Markdown
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