OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
6 Code distributed by Google as part of the polymer project is also | 6 Code distributed by Google as part of the polymer project is also |
7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
8 --> | 8 --> |
9 <link rel="import" href="../polymer/polymer.html"> | 9 <link rel="import" href="../polymer/polymer.html"> |
10 <link rel="import" href="../observe-js/observe-js.html"> | |
11 | 10 |
12 <link rel="import" href="more-route-context-aware.html"> | 11 <link rel="import" href="more-route-context-aware.html"> |
13 <link rel="import" href="route.html"> | 12 <link rel="import" href="route.html"> |
14 | 13 |
15 <!-- | 14 <!-- |
16 TODO(nevir): Document. | 15 TODO(nevir): Document. |
17 --> | 16 --> |
18 <script> | 17 <script> |
19 | 18 |
20 Polymer({ | 19 Polymer({ |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 }.bind(this))); | 110 }.bind(this))); |
112 | 111 |
113 this._observeRoutes(); | 112 this._observeRoutes(); |
114 this._evaluate(); | 113 this._evaluate(); |
115 }, | 114 }, |
116 | 115 |
117 /** | 116 /** |
118 * Tracks changes to the routes. | 117 * Tracks changes to the routes. |
119 */ | 118 */ |
120 _observeRoutes: function() { | 119 _observeRoutes: function() { |
121 if (this._observer) { | 120 if (this._routeListeners) { |
122 this._observer.close(); | 121 for (var i = 0, listener; listener = this._routeListeners[i]; i++) { |
| 122 listener.close(); |
| 123 } |
123 } | 124 } |
124 // TODO(nevir): https://github.com/Polymore/more-routing/issues/24 | 125 |
125 this._observer = new CompoundObserver(); | 126 this._routeListeners = this._routeInfo.map(function(routeInfo) { |
126 for (var i = 0, routeInfo; routeInfo = this._routeInfo[i]; i++) { | 127 return routeInfo.model.__subscribe(this._evaluate.bind(this)); |
127 this._observer.addPath(routeInfo.model, 'active'); | 128 }.bind(this)); |
128 } | |
129 this._observer.open(this._evaluate.bind(this)); | |
130 }, | 129 }, |
131 | 130 |
132 _evaluate: function() { | 131 _evaluate: function() { |
133 var newIndex = -1; | 132 var newIndex = -1; |
134 var newRoute = null; | 133 var newRoute = null; |
135 var oldIndex = this.selectedIndex; | 134 var oldIndex = this.selectedIndex; |
136 | 135 |
137 for (var i = 0, routeInfo; routeInfo = this._routeInfo[i]; i++) { | 136 for (var i = 0, routeInfo; routeInfo = this._routeInfo[i]; i++) { |
138 if (routeInfo.model && routeInfo.model.active) { | 137 if (routeInfo.model && routeInfo.model.active) { |
139 newIndex = routeInfo.index; | 138 newIndex = routeInfo.index; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 // Equally specific; we fall back to the default (and hopefully | 188 // Equally specific; we fall back to the default (and hopefully |
190 // stable) sort order. | 189 // stable) sort order. |
191 return 0; | 190 return 0; |
192 } | 191 } |
193 } | 192 } |
194 }); | 193 }); |
195 }, | 194 }, |
196 | 195 |
197 }); | 196 }); |
198 </script> | 197 </script> |
OLD | NEW |