-
Notifications
You must be signed in to change notification settings - Fork 816
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
Need to bind strategies handle
method
#2171
Comments
Yeah, we can definitely do this. Just to confirm though, are you saying you didn't need to bind in v4? Looking at the v4 code it doesn't look like we ever bound the |
I was using the I only started using the v5 alpha because I wanted to add some extra logic in my service worker (using the |
Hmmm, after thinking about this a bit more, it occurred to me that I've never had this problem and I import the strategy classes exactly the same way you do. Did you try passing the strategy class instance directly to E.g. did you try this: registerRoute(JS_CSS_REGEX, assetsHandler) Instead of this: registerRoute(JS_CSS_REGEX, assetsHandler.handle) Or this? registerRoute(JS_CSS_REGEX, assetsHandler.handle.bind(assetsHandler)) |
yeah, I did try that, but I think the typings for the I'm getting this TypeScript error:
|
Library Affected:
workbox-strategies
Browser & Platform:
Not applicable.
Issue or Feature Request Description:
I've noticed while developing using the
v5.0.0-alpha.2
that you need to manually call.bind()
on the strategieshandle
method, since they are normal JavaScript classes methods, making the service worker code a little more bloated than it should be.Here is an example of what I'm trying to say:
You can see that the
assetsHandler.handle.bind(assetsHandler)
could become a little annoying to write when you have severalregisterRoute
callbacks combined with multiple configurations for different routes (since you'll have to extract the instance of the strategy to a variable and call.bind
on thehandle
method).I'm proposing to change the
handle
method on the strategies classes to use an arrow function or to manually bind them in the constructor of the class so the DX could be a little better.The text was updated successfully, but these errors were encountered: