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

Adds JSDocs for the lifecycle methods, and awaits the return of each. #736

Merged
merged 1 commit into from
Aug 10, 2017

Conversation

jeffposnick
Copy link
Contributor

R: @addyosmani @gauntface

Fixes #709, fixes #533

await is nice in that it doesn't require the expression to actually evaluate to a promise So both await Promise.resolve(true) and await true are both valid.

Because of this, I just had to change the code that calls the lifecycle methods to consistently use await, and the existing plugins that don't need to do anything asynchronous don't have to be updated.

This opens the doors for new plugins that weren't previously able to return promises, like the Range request helper in #710.

I took the opportunity to add in formal JSDoc for the lifecycle methods, via @callback, since that was a longstanding issue.

@jeffposnick jeffposnick added the Breaking Change Denotes a "major" semver change. label Aug 10, 2017
const returnedPromise = plugin.requestWillFetch({request});
isInstance({returnedPromise}, Promise);
const returnedRequest = await returnedPromise;
const returnedRequest = await plugin.requestWillFetch({request});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is equivalent to what was there before; because I'm now using await, the return value from plugin.requestWillFetch() will always be a promise.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the note. The return value here always being a promise looks fine with your update.

Copy link
Member

@addyosmani addyosmani left a comment

Choose a reason for hiding this comment

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

LGTM. I didn't see anything that struck me as out of place while reading through.

@gauntface gauntface merged commit ab55495 into v2 Aug 10, 2017
@gauntface gauntface deleted the lifecycle-methods-return-promise branch August 10, 2017 21:07
gauntface pushed a commit that referenced this pull request Aug 24, 2017
* Adds JSDocs for the lifecycle methods, and awaits the return of each. (#736)

* Move towards using 'workbox' over 'workbox-cli'. (#744)

* New library to support Range requests (#710)

* WIP.

* Still needs JSDocs.

* Renaming, bug fixes, JSDoc.

* Changed a few comments.

* Updated tests to use new bundling infra, allowing us to remove private exports.

* Modified a warning.

* Rename cacheWillMatch to cachedResponseWillBeUsed (#748)

* No longer register a fetch handler for each Router by default (#752)

* No longer register a fetch handler for each Router by default.

* Review feedback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Denotes a "major" semver change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants