-
Notifications
You must be signed in to change notification settings - Fork 824
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
Decouple Router~handleRequest from events #1682
Conversation
7e20042
to
6a2289d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of small things, but otherwise 👍
I'm on board, I hope this makes the "pass in a list of URLs and have them handled" code you're trying to write cleaner.
* @param {URL} options.url | ||
* @param {Request} options.request | ||
* @param {Event} [options.event] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove options.event
from the JSDoc.
let handler = null; | ||
let params = null; | ||
let debugMessages = []; | ||
let {params, route} = this.findMatchingRoute({url, request, event}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like all these let
s can be changed to const
after your refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
route
gets reassigned and params
doesn't, but since one of them does, in order to use destructuring I had to do both as let...
6a2289d
to
cd5c5e6
Compare
cd5c5e6
to
6e5dd96
Compare
PR-Bot Size PluginChanged File Sizes
New FilesNo new files have been added. All File SizesView Table
Workbox Aggregate Size Plugin9.43KB gzip'ed (63% of limit) |
R: @jeffposnick
Fixes #1630
This PR updates the routing and strategy packages in a few ways.
Breaking changes:
the
Router~handleRequest()
method from just taking anEvent
object, to taking anoptions
object whereoptions.request
is required andoptions.event
is optional. Note that technically this change is mostly backwards compatible with the previous version since fetch events have arequest
property. One thing to watch out for, though, is if people were using this method directly and passing an event, no strategies or handlers would be able to callevent.waitUntil()
. We could support both aFetchEvent
argument as well an optionsObject
argument -- or we could just consider this a breaking change and provide upgrade instructions.The strategy classes'
handle()
methods no longer require anoptions.event
parameter, and they now work essentially the same as theirmakeRequest
methods. With this change, we don't really need two separate methods, so we may want to consider getting rid of one of them.The
match
andhandler
callbacks are now also passed anoptions.request
in addition tooptions.url
, and optionallyoptions.event
. I'm not sure if anyone was ever using theoptions.event
property, but sinceRouter~handleRequest()
can now be called without an event,options.event
will now sometimes not be present and so is thus documented as an optional argument.Probably more of a bug fix than a breaking change, but previous if a match callback returned a truthy string, that string would be passed as the
options.params
argument to the handler. I'm assuming this wasn't intentional, so I've now updated that logic to only passoptions.params
if the return value is a non-empty object or array.Non-breaking changes:
Router~_findHandlerAndParams()
method and renamed it tofindMatchingRoute()
, meaning it's now a public method. I figure it may be useful for someone who wants to use the router without executing a handler right away.