source: frontend/node_modules/workbox-routing/src/Route.ts

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 Copyright 2018 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8
9import {assert} from 'workbox-core/_private/assert.js';
10import {HTTPMethod, defaultMethod, validMethods} from './utils/constants.js';
11import {normalizeHandler} from './utils/normalizeHandler.js';
12import {
13 RouteHandler,
14 RouteHandlerObject,
15 RouteMatchCallback,
16} from 'workbox-core/types.js';
17import './_version.js';
18
19/**
20 * A `Route` consists of a pair of callback functions, "match" and "handler".
21 * The "match" callback determine if a route should be used to "handle" a
22 * request by returning a non-falsy value if it can. The "handler" callback
23 * is called when there is a match and should return a Promise that resolves
24 * to a `Response`.
25 *
26 * @memberof workbox-routing
27 */
28class Route {
29 handler: RouteHandlerObject;
30 match: RouteMatchCallback;
31 method: HTTPMethod;
32 catchHandler?: RouteHandlerObject;
33
34 /**
35 * Constructor for Route class.
36 *
37 * @param {workbox-routing~matchCallback} match
38 * A callback function that determines whether the route matches a given
39 * `fetch` event by returning a non-falsy value.
40 * @param {workbox-routing~handlerCallback} handler A callback
41 * function that returns a Promise resolving to a Response.
42 * @param {string} [method='GET'] The HTTP method to match the Route
43 * against.
44 */
45 constructor(
46 match: RouteMatchCallback,
47 handler: RouteHandler,
48 method: HTTPMethod = defaultMethod,
49 ) {
50 if (process.env.NODE_ENV !== 'production') {
51 assert!.isType(match, 'function', {
52 moduleName: 'workbox-routing',
53 className: 'Route',
54 funcName: 'constructor',
55 paramName: 'match',
56 });
57
58 if (method) {
59 assert!.isOneOf(method, validMethods, {paramName: 'method'});
60 }
61 }
62
63 // These values are referenced directly by Router so cannot be
64 // altered by minificaton.
65 this.handler = normalizeHandler(handler);
66 this.match = match;
67 this.method = method;
68 }
69
70 /**
71 *
72 * @param {workbox-routing-handlerCallback} handler A callback
73 * function that returns a Promise resolving to a Response
74 */
75 setCatchHandler(handler: RouteHandler): void {
76 this.catchHandler = normalizeHandler(handler);
77 }
78}
79
80export {Route};
Note: See TracBrowser for help on using the repository browser.