Chromium Code Reviews| 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 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 r.SYSTEM = r.ADVANCED.createSection('/system', 'system'); | 204 r.SYSTEM = r.ADVANCED.createSection('/system', 'system'); |
| 205 r.RESET = r.ADVANCED.createSection('/reset', 'reset'); | 205 r.RESET = r.ADVANCED.createSection('/reset', 'reset'); |
| 206 | 206 |
| 207 // <if expr="chromeos"> | 207 // <if expr="chromeos"> |
| 208 // "About" is the only section in About, but we still need to create the route | 208 // "About" is the only section in About, but we still need to create the route |
| 209 // in order to show the subpage on Chrome OS. | 209 // in order to show the subpage on Chrome OS. |
| 210 r.ABOUT_ABOUT = r.ABOUT.createSection('/help/about', 'about'); | 210 r.ABOUT_ABOUT = r.ABOUT.createSection('/help/about', 'about'); |
| 211 r.DETAILED_BUILD_INFO = r.ABOUT_ABOUT.createChild('/help/details'); | 211 r.DETAILED_BUILD_INFO = r.ABOUT_ABOUT.createChild('/help/details'); |
| 212 // </if> | 212 // </if> |
| 213 | 213 |
| 214 var routeObservers_ = new Set(); | 214 var routeObservers_ = new Set(); |
|
Dan Beam
2017/01/21 00:47:50
need to make this an array or something
dpapad
2017/01/21 00:55:49
Done, with Array.from(). Let's see if the compiler
dpapad
2017/01/21 01:02:47
Changed to Set#forEach, to avoid the unnecessary c
| |
| 215 | 215 |
| 216 /** @polymerBehavior */ | 216 /** @polymerBehavior */ |
| 217 var RouteObserverBehavior = { | 217 var RouteObserverBehavior = { |
| 218 /** @override */ | 218 /** @override */ |
| 219 attached: function() { | 219 attached: function() { |
| 220 assert(!routeObservers_.has(this)); | 220 assert(!routeObservers_.has(this)); |
| 221 routeObservers_.add(this); | 221 routeObservers_.add(this); |
| 222 | 222 |
| 223 // Emulating Polymer data bindings, the observer is called when the | 223 // Emulating Polymer data bindings, the observer is called when the |
| 224 // element starts observing the route. | 224 // element starts observing the route. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 * Helper function to set the current route and notify all observers. | 305 * Helper function to set the current route and notify all observers. |
| 306 * @param {!settings.Route} route | 306 * @param {!settings.Route} route |
| 307 * @param {!URLSearchParams} queryParameters | 307 * @param {!URLSearchParams} queryParameters |
| 308 * @param {boolean} isPopstate | 308 * @param {boolean} isPopstate |
| 309 */ | 309 */ |
| 310 var setCurrentRoute = function(route, queryParameters, isPopstate) { | 310 var setCurrentRoute = function(route, queryParameters, isPopstate) { |
| 311 var oldRoute = currentRoute_; | 311 var oldRoute = currentRoute_; |
| 312 currentRoute_ = route; | 312 currentRoute_ = route; |
| 313 currentQueryParameters_ = queryParameters; | 313 currentQueryParameters_ = queryParameters; |
| 314 lastRouteChangeWasPopstate_ = isPopstate; | 314 lastRouteChangeWasPopstate_ = isPopstate; |
| 315 for (var observer of routeObservers_) | 315 for (var i = 0; i < routeObservers_.length; i++) |
| 316 observer.currentRouteChanged(currentRoute_, oldRoute); | 316 routeObservers_[i].currentRouteChanged(currentRoute_, oldRoute); |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 /** @return {!settings.Route} */ | 319 /** @return {!settings.Route} */ |
| 320 var getCurrentRoute = function() { return currentRoute_; }; | 320 var getCurrentRoute = function() { return currentRoute_; }; |
| 321 | 321 |
| 322 /** @return {!URLSearchParams} */ | 322 /** @return {!URLSearchParams} */ |
| 323 var getQueryParameters = function() { | 323 var getQueryParameters = function() { |
| 324 return new URLSearchParams(currentQueryParameters_); // Defensive copy. | 324 return new URLSearchParams(currentQueryParameters_); // Defensive copy. |
| 325 }; | 325 }; |
| 326 | 326 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 RouteObserverBehavior: RouteObserverBehavior, | 384 RouteObserverBehavior: RouteObserverBehavior, |
| 385 getRouteForPath: getRouteForPath, | 385 getRouteForPath: getRouteForPath, |
| 386 initializeRouteFromUrl: initializeRouteFromUrl, | 386 initializeRouteFromUrl: initializeRouteFromUrl, |
| 387 getCurrentRoute: getCurrentRoute, | 387 getCurrentRoute: getCurrentRoute, |
| 388 getQueryParameters: getQueryParameters, | 388 getQueryParameters: getQueryParameters, |
| 389 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, | 389 lastRouteChangeWasPopstate: lastRouteChangeWasPopstate, |
| 390 navigateTo: navigateTo, | 390 navigateTo: navigateTo, |
| 391 navigateToPreviousRoute: navigateToPreviousRoute, | 391 navigateToPreviousRoute: navigateToPreviousRoute, |
| 392 }; | 392 }; |
| 393 }); | 393 }); |
| OLD | NEW |