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

Unified Diff: third_party/polymer/v0_8/components-chromium/more-routing/route-extracted.js

Issue 1140393002: Update more-routing for md-settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v0_8/components-chromium/more-routing/route-extracted.js
diff --git a/third_party/polymer/v0_8/components-chromium/more-routing/route-extracted.js b/third_party/polymer/v0_8/components-chromium/more-routing/route-extracted.js
index abf24cd2ee91c400e555030645a3a114c3aadde3..6f6e6fa1a85524775e726550d0c15add0a51713b 100644
--- a/third_party/polymer/v0_8/components-chromium/more-routing/route-extracted.js
+++ b/third_party/polymer/v0_8/components-chromium/more-routing/route-extracted.js
@@ -14,6 +14,9 @@ var SEPARATOR_CLEANER = /\/\/+/g;
* TODO(nevir): Docs.
*/
function Route(path, parent) {
+ // For `MoreRouting.Emitter`; Emits changes for `active`.
+ this.__listeners = [];
+
this.path = path;
this.parent = parent;
this.fullPath = path;
@@ -21,6 +24,13 @@ function Route(path, parent) {
this.active = false;
this.driver = null;
+ var params = MoreRouting.Params(namedParams(this.compiled), this.parent && this.parent.params);
+ params.__subscribe(this._navigateToParams.bind(this));
+ Object.defineProperty(this, 'params', {
+ get: function() { return params; },
+ set: function() { throw new Error('Route#params cannot be overwritten'); },
+ });
+
this.parts = [];
this.children = [];
@@ -29,20 +39,27 @@ function Route(path, parent) {
// To make data "binding" easy, `Route` guarantees that `params` will always
// be the same object; just make a reference to it.
if (this.parent) {
- this.params = Object.create(this.parent.params);
this.parent.children.push(this);
this.fullPath = this.parent.fullPath + this.fullPath;
this.depth = this.parent.depth + this.compiled.length;
this.numParams = this.parent.numParams + countParams(this.compiled);
} else {
- this.params = {};
this.depth = this.compiled.length;
this.numParams = countParams(this.compiled);
}
-
- this._paramObserver = new ObjectObserver(this.params);
- this._paramObserver.open(this._navigateToParams.bind(this));
}
+Route.prototype = Object.create(MoreRouting.Emitter);
+
+Object.defineProperty(Route.prototype, 'active', {
+ get: function() {
+ return this._active;
+ },
+ set: function(value) {
+ if (value !== this._active);
+ this._active = value;
+ this.__notify('active', value);
+ },
+});
Route.isPath = function isPath(pathOrName) {
return pathOrName.indexOf(PART_SEPARATOR) === 0;
@@ -115,6 +132,10 @@ Route.prototype.partsForParams = function partsForParams(params, silent) {
Route.prototype.processPathParts = function processPathParts(parts) {
this.parts = parts;
this.active = this.matchesPathParts(parts);
+
+ // We don't want to notify of these changes; they'd be no-op noise.
+ this.params.__silent = true;
+
if (this.active) {
var keys = Object.keys(this.params);
for (var i = 0; i < keys.length; i++) {
@@ -130,7 +151,8 @@ Route.prototype.processPathParts = function processPathParts(parts) {
this.params[key] = undefined;
}
}
- this._paramObserver.discardChanges();
+
+ delete this.params.__silent;
};
Route.prototype.matchesPathParts = function matchesPathParts(parts) {
@@ -180,4 +202,13 @@ function countParams(compiled) {
}, 0);
}
+function namedParams(compiled) {
+ var result = [];
+ compiled.forEach(function(part) {
+ if (part.type === 'static') return;
+ result.push(part.name);
+ });
+ return result;
+}
+
})(window);

Powered by Google App Engine
This is Rietveld 408576698