8 MoreRouting.ContextAware,
14 * The name of this route. Behavior differs based on the presence of
15 * `path` during _declaration_.
17 * If `path` is present during declaration, it is registered via `name`.
19 * Otherwise, this `more-route` becomes a `reference` to the route with
20 * `name`. Changing `name` will update which route is referenced.
24 observer: '_nameChanged',
28 * A path expression used to parse parameters from the window's URL.
32 obserer: '_pathChanged',
36 * Whether this route should become a context for the element that
44 * The underlying `MoreRouting.Route` object that is being wrapped.
46 * @type {MoreRouting.Route}
52 observer: '_routeChanged',
56 * The full path expression for this route, including routes this is
66 * Param values matching the current URL, or an empty object if not
76 * Whether the route matches the current URL.
86 routingReady: function() {
87 this._identityChanged();
90 _nameChanged: function(newName, oldName) {
92 console.error('Changing the `name` property is not supported for', this);
95 this._identityChanged();
98 _pathChanged: function(newPath, oldPath) {
100 console.error('Changing the `path` property is not supported for', this);
103 this._identityChanged();
106 _identityChanged: function() {
107 if (!this.routingIsReady) return;
109 if (this.name && this.path) {
110 this._setRoute(MoreRouting.registerNamedRoute(this.name, this.path, this.parentRoute));
111 } else if (this.name) {
112 this._setRoute(MoreRouting.getRouteByName(this.name));
113 } else if (this.path) {
114 this._setRoute(MoreRouting.getRouteByPath(this.path, this.parentRoute));
116 this._setRoute(null);
120 _routeChanged: function() {
121 this._observeRoute();
122 this._setFullPath(this.route.fullPath);
123 // this._setParams(this.route.params);
124 this.params = this.route.params;
125 this._setActive(this.route.active);
127 // @see MoreRouting.ContextAware
128 this.moreRouteContext = this.route;
131 var parent = Polymer.dom(this).parentNode;
132 if (parent.nodeType !== Node.ELEMENT_NODE) {
133 parent = parent.host;
136 if (parent.nodeType === Node.ELEMENT_NODE) {
137 parent.moreRouteContext = this.route;
139 console.warn('Unable to determine parent element for', this, '- not setting a context');
144 _observeRoute: function() {
145 // TODO(nevir) https://github.com/Polymore/more-routing/issues/24
146 if (this._routeListener) {
147 this._routeListener.close();
148 this._routeListener = null;
150 if (this._paramListener) {
151 this._paramListener.close();
152 this._paramListener = null;
154 if (!this.route) return;
156 this._routeListener = this.route.__subscribe(function() {
157 this._setActive(this.route && this.route.active);
160 this._paramListener = this.route.params.__subscribe(function(key, value) {
161 // https://github.com/Polymer/polymer/issues/1505
162 this.notifyPath('params.' + key, value);
166 urlFor: function(params) {
167 return this.route.urlFor(params);
170 navigateTo: function(params) {
171 return this.route.navigateTo(params);
174 isCurrentUrl: function(params) {
175 return this.route.isCurrentUrl(params);