OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Specifies all possible routes in settings. | 6 * Specifies all possible routes in settings. |
7 * | 7 * |
8 * @typedef {{ | 8 * @typedef {{ |
9 * ABOUT: (undefined|!settings.Route), | 9 * ABOUT: (undefined|!settings.Route), |
10 * ABOUT_ABOUT: (undefined|!settings.Route), | 10 * ABOUT_ABOUT: (undefined|!settings.Route), |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 * Helper function to set the current route and notify all observers. | 422 * Helper function to set the current route and notify all observers. |
423 * @param {!settings.Route} route | 423 * @param {!settings.Route} route |
424 * @param {!URLSearchParams} queryParameters | 424 * @param {!URLSearchParams} queryParameters |
425 * @param {boolean} isPopstate | 425 * @param {boolean} isPopstate |
426 */ | 426 */ |
427 setCurrentRoute(route, queryParameters, isPopstate) { | 427 setCurrentRoute(route, queryParameters, isPopstate) { |
428 var oldRoute = this.currentRoute; | 428 var oldRoute = this.currentRoute; |
429 this.currentRoute = route; | 429 this.currentRoute = route; |
430 this.currentQueryParameters_ = queryParameters; | 430 this.currentQueryParameters_ = queryParameters; |
431 this.wasLastRouteChangePopstate_ = isPopstate; | 431 this.wasLastRouteChangePopstate_ = isPopstate; |
432 routeObservers.forEach(function(observer) { | 432 routeObservers.forEach(observer => { |
433 observer.currentRouteChanged(this.currentRoute, oldRoute); | 433 observer.currentRouteChanged(this.currentRoute, oldRoute); |
434 }.bind(this)); | 434 }); |
435 } | 435 } |
436 | 436 |
437 /** @return {!settings.Route} */ | 437 /** @return {!settings.Route} */ |
438 getCurrentRoute() { | 438 getCurrentRoute() { |
439 return this.currentRoute; | 439 return this.currentRoute; |
440 } | 440 } |
441 | 441 |
442 /** @return {!URLSearchParams} */ | 442 /** @return {!URLSearchParams} */ |
443 getQueryParameters() { | 443 getQueryParameters() { |
444 return new URLSearchParams( | 444 return new URLSearchParams( |
445 this.currentQueryParameters_); // Defensive copy. | 445 this.currentQueryParameters_); // Defensive copy. |
446 } | 446 } |
447 | 447 |
448 /** @return {boolean} */ | 448 /** @return {boolean} */ |
449 lastRouteChangeWasPopstate() { | 449 lastRouteChangeWasPopstate() { |
450 return this.wasLastRouteChangePopstate_; | 450 return this.wasLastRouteChangePopstate_; |
451 } | 451 } |
452 | 452 |
453 /** | 453 /** |
454 * @param {string} path | 454 * @param {string} path |
455 * @return {?settings.Route} The matching canonical route, or null if none | 455 * @return {?settings.Route} The matching canonical route, or null if none |
456 * matches. | 456 * matches. |
457 */ | 457 */ |
458 getRouteForPath(path) { | 458 getRouteForPath(path) { |
459 // Allow trailing slash in paths. | 459 // Allow trailing slash in paths. |
460 var canonicalPath = path.replace(CANONICAL_PATH_REGEX, '$1$2'); | 460 var canonicalPath = path.replace(CANONICAL_PATH_REGEX, '$1$2'); |
461 | 461 |
462 // TODO(tommycli): Use Object.values once Closure compilation supports it. | 462 // TODO(tommycli): Use Object.values once Closure compilation supports it. |
463 var matchingKey = Object.keys(this.routes_).find(function(key) { | 463 var matchingKey = |
464 return this.routes_[key].path == canonicalPath; | 464 Object.keys(this.routes_) |
465 }.bind(this)); | 465 .find(key => this.routes_[key].path == canonicalPath); |
466 | 466 |
467 return !!matchingKey ? this.routes_[matchingKey] : null; | 467 return !!matchingKey ? this.routes_[matchingKey] : null; |
468 } | 468 } |
469 | 469 |
470 /** | 470 /** |
471 * Navigates to a canonical route and pushes a new history entry. | 471 * Navigates to a canonical route and pushes a new history entry. |
472 * @param {!settings.Route} route | 472 * @param {!settings.Route} route |
473 * @param {URLSearchParams=} opt_dynamicParameters Navigations to the same | 473 * @param {URLSearchParams=} opt_dynamicParameters Navigations to the same |
474 * URL parameters in a different order will still push to history. | 474 * URL parameters in a different order will still push to history. |
475 * @param {boolean=} opt_removeSearch Whether to strip the 'search' URL | 475 * @param {boolean=} opt_removeSearch Whether to strip the 'search' URL |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 getRouteForPath: getRouteForPath, | 620 getRouteForPath: getRouteForPath, |
621 initializeRouteFromUrl: initializeRouteFromUrl, | 621 initializeRouteFromUrl: initializeRouteFromUrl, |
622 resetRouteForTesting: resetRouteForTesting, | 622 resetRouteForTesting: resetRouteForTesting, |
623 getCurrentRoute: getCurrentRoute, | 623 getCurrentRoute: getCurrentRoute, |
624 getQueryParameters: getQueryParameters, | 624 getQueryParameters: getQueryParameters, |
625 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, | 625 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, |
626 navigateTo: navigateTo, | 626 navigateTo: navigateTo, |
627 navigateToPreviousRoute: navigateToPreviousRoute, | 627 navigateToPreviousRoute: navigateToPreviousRoute, |
628 }; | 628 }; |
629 }); | 629 }); |
OLD | NEW |