ApplicationImpl cleanup, part 1:
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / more-routing / more-route-extracted.js
blob549aadf39b19c50ccce58ec0bf12897f653750a3
3 Polymer({
5 is: 'more-route',
7 behaviors: [
8 MoreRouting.ContextAware,
9 ],
11 properties: {
13 /**
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.
22 name: {
23 type: String,
24 observer: '_nameChanged',
27 /**
28 * A path expression used to parse parameters from the window's URL.
30 path: {
31 type: String,
32 obserer: '_pathChanged',
35 /**
36 * Whether this route should become a context for the element that
37 * contains it.
39 context: {
40 type: Boolean,
43 /**
44 * The underlying `MoreRouting.Route` object that is being wrapped.
46 * @type {MoreRouting.Route}
48 route: {
49 type: Object,
50 readOnly: true,
51 notify: true,
52 observer: '_routeChanged',
55 /**
56 * The full path expression for this route, including routes this is
57 * nested within.
59 fullPath: {
60 type: String,
61 readOnly: true,
62 notify: true,
65 /**
66 * Param values matching the current URL, or an empty object if not
67 * `active`.
69 params: {
70 type: Object,
71 // readOnly: true,
72 notify: true,
75 /**
76 * Whether the route matches the current URL.
78 active: {
79 type: Boolean,
80 readOnly: true,
81 notify: true,
86 routingReady: function() {
87 this._identityChanged();
90 _nameChanged: function(newName, oldName) {
91 if (oldName) {
92 console.error('Changing the `name` property is not supported for', this);
93 return;
95 this._identityChanged();
98 _pathChanged: function(newPath, oldPath) {
99 if (oldPath) {
100 console.error('Changing the `path` property is not supported for', this);
101 return;
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));
115 } else {
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;
130 if (this.context) {
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;
138 } else {
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);
158 }.bind(this));
160 this._paramListener = this.route.params.__subscribe(function(key, value) {
161 // https://github.com/Polymer/polymer/issues/1505
162 this.notifyPath('params.' + key, value);
163 }.bind(this));
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);