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

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

Issue 2141313002: Settings Router Refactor: Implement new Route class w/ test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('settings', function() {
6 /**
7 * Class for navigable routes. May only be instantiated within this file.
8 * @private
michaelpg 2016/07/13 05:53:39 optional CL-wide nit: our convention is to put @pr
tommycli 2016/07/13 17:45:03 Done.
9 * @constructor
10 * @param {string} url
11 */
12 var Route = function(url) {
13 /** @type {string} */
michaelpg 2016/07/13 05:53:39 closure doesn't infer this?
tommycli 2016/07/13 17:45:03 Done.
14 this.url = url;
15
16 /** @type {settings.Route} */
michaelpg 2016/07/13 05:53:39 {?settings.Route}
tommycli 2016/07/13 17:45:03 Done.
17 this.parent = null;
18
19 // Below are all legacy properties to provide compatibility with the old
20 // routing system. TODO(tommycli): Remove once routing refactor complete.
21
22 /** @type {string} */
michaelpg 2016/07/13 05:53:39 same questions about types
tommycli 2016/07/13 17:45:03 Done.
23 this.page = '';
24
25 /** @type {string} */
26 this.section = '';
27
28 /** @type {!Array<string>} */
29 this.subpage = [];
30
31 /** @type {boolean} */
32 this.dialog = false;
33 };
34
35 Route.prototype = {
36 /**
37 * Returns a new Route instance that's a child of this route.
38 * @private
39 * @param {string} url
40 * @param {string=} opt_subpageName
41 * @return {!settings.Route}
42 */
43 createChild: function(url, opt_subpageName) {
44 var route = new Route(url);
45 route.parent = this;
46 route.page = this.page;
47 route.section = this.section;
48
49 if (opt_subpageName)
50 route.subpage.push(opt_subpageName);
51
52 return route;
53 },
54
55 /**
56 * Return a new Route instance that's a child dialog of this route.
michaelpg 2016/07/13 05:53:39 Returns
tommycli 2016/07/13 17:45:03 Done.
57 * @private
58 * @param {string} url
59 * @return {!settings.Route}
60 */
61 createDialog: function(url) {
62 var route = this.createChild(url);
63 route.dialog = true;
64 return route;
65 },
66
67 /**
68 * Returns true if this route is a descendant of the parameter.
69 * @param {!settings.Route} route
70 * @return {boolean}
71 */
72 isDescendantOf: function(route) {
73 for (var parent = this.parent; parent != null; parent = parent.parent) {
74 if (route == parent)
75 return true;
76 }
77
78 return false;
79 },
80 };
81
82 return {
83 Route: Route,
84 };
85 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698