Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: chrome/browser/resources/settings/route.js

Issue 2242863002: Settings Router Refactor: Allow no-op navigations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/settings/settings_main/settings_main.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 cr.define('settings', function() { 5 cr.define('settings', function() {
6 /** 6 /**
7 * Class for navigable routes. May only be instantiated within this file. 7 * Class for navigable routes. May only be instantiated within this file.
8 * @constructor 8 * @constructor
9 * @param {string} path 9 * @param {string} path
10 * @private 10 * @private
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 339
340 /** 340 /**
341 * Navigates to a canonical route and pushes a new history entry. 341 * Navigates to a canonical route and pushes a new history entry.
342 * @param {!settings.Route} route 342 * @param {!settings.Route} route
343 * @param {URLSearchParams=} opt_dynamicParameters Navigations to the same 343 * @param {URLSearchParams=} opt_dynamicParameters Navigations to the same
344 * search parameters in a different order will still push to history. 344 * search parameters in a different order will still push to history.
345 * @private 345 * @private
346 */ 346 */
347 var navigateTo = function(route, opt_dynamicParameters) { 347 var navigateTo = function(route, opt_dynamicParameters) {
348 var params = opt_dynamicParameters || new URLSearchParams(); 348 var params = opt_dynamicParameters || new URLSearchParams();
349 if (assert(route) == currentRoute_ &&
350 params.toString() == currentQueryParameters_.toString()) {
351 return;
352 }
353 349
354 var url = route.path; 350 var url = route.path;
355 if (opt_dynamicParameters) { 351 if (opt_dynamicParameters) {
356 var queryString = opt_dynamicParameters.toString(); 352 var queryString = opt_dynamicParameters.toString();
357 if (queryString) 353 if (queryString)
358 url += '?' + queryString; 354 url += '?' + queryString;
359 } 355 }
360 356
361 // History serializes the state, so we don't push the actual route object. 357 // History serializes the state, so we don't push the actual route object.
362 var previousRoutePath = currentRoute_.path; 358 var previousRoutePath = currentRoute_.path;
363 setCurrentRoute(route, params); 359 setCurrentRoute(route, params);
364 window.history.pushState(previousRoutePath, '', url); 360 window.history.pushState(previousRoutePath, '', url);
365 }; 361 };
366 362
367 window.addEventListener('popstate', function(event) { 363 window.addEventListener('popstate', function(event) {
368 // On pop state, do not push the state onto the window.history again. 364 // On pop state, do not push the state onto the window.history again.
369 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC, 365 setCurrentRoute(getRouteForPath(window.location.pathname) || Route.BASIC,
370 new URLSearchParams(window.location.search)); 366 new URLSearchParams(window.location.search));
371 }); 367 });
372 368
373 return { 369 return {
374 Route: Route, 370 Route: Route,
375 RouteObserverBehavior: RouteObserverBehavior, 371 RouteObserverBehavior: RouteObserverBehavior,
376 getRouteForPath: getRouteForPath, 372 getRouteForPath: getRouteForPath,
377 getCurrentRoute: getCurrentRoute, 373 getCurrentRoute: getCurrentRoute,
378 getQueryParameters: getQueryParameters, 374 getQueryParameters: getQueryParameters,
379 navigateTo: navigateTo, 375 navigateTo: navigateTo,
380 }; 376 };
381 }); 377 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/settings/settings_main/settings_main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698