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

Upgrade Workbox to v4.0.0-alpha.0 #98

Merged
merged 6 commits into from
Oct 30, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions wp-includes/js/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ wp.serviceWorker = workbox;
*/
class WPRouter extends wp.serviceWorker.routing.Router {

_findHandlerAndParams( event, url ) {
const routes = this._routes.get( event.request.method ) || [];
findMatchingRoute( {
url,
request,
event
} ) {
const routes = this._routes.get( request.method ) || [];
let matches = 0,
matchResult,
firstMatch;
for ( const route of routes ) {
matchResult = route.match( { url, event } );
matchResult = route.match( { url, request, event } );
if ( matchResult ) {
matches++;

Expand All @@ -39,16 +43,15 @@ wp.serviceWorker = workbox;

firstMatch = {
route,
params: matchResult,
handler: route.handler
params: matchResult
};
}
}
}

// If we didn't have a match, then return undefined values.
if ( 0 === matches ) {
return { handler: undefined, params: undefined };
return { route: undefined, params: undefined };
} else {
// Log conflicting routes and return the first.
if ( 1 < matches ) {
Expand Down Expand Up @@ -143,7 +146,8 @@ wp.serviceWorker = workbox;

// @todo There is another 'fetch' handler being for DefaultRouter added in the workbox-routing module which will be unused since.
self.addEventListener( 'fetch', event => {
const responsePromise = wp.serviceWorker.routing.handleRequest( event );
const request = event.request;
const responsePromise = wp.serviceWorker.routing.handleRequest( { request, event } );
if ( responsePromise ) {
event.respondWith( responsePromise );
}
Expand Down