OLD | NEW |
1 | 1 |
2 | 2 |
3 Polymer({ | 3 Polymer({ |
4 | 4 |
5 is: 'more-route-selection', | 5 is: 'more-route-selection', |
6 | 6 |
7 behaviors: [ | 7 behaviors: [ |
8 MoreRouting.ContextAware, | 8 MoreRouting.ContextAware, |
9 ], | 9 ], |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 }.bind(this))); | 94 }.bind(this))); |
95 | 95 |
96 this._observeRoutes(); | 96 this._observeRoutes(); |
97 this._evaluate(); | 97 this._evaluate(); |
98 }, | 98 }, |
99 | 99 |
100 /** | 100 /** |
101 * Tracks changes to the routes. | 101 * Tracks changes to the routes. |
102 */ | 102 */ |
103 _observeRoutes: function() { | 103 _observeRoutes: function() { |
104 if (this._observer) { | 104 if (this._routeListeners) { |
105 this._observer.close(); | 105 for (var i = 0, listener; listener = this._routeListeners[i]; i++) { |
| 106 listener.close(); |
| 107 } |
106 } | 108 } |
107 // TODO(nevir): https://github.com/Polymore/more-routing/issues/24 | 109 |
108 this._observer = new CompoundObserver(); | 110 this._routeListeners = this._routeInfo.map(function(routeInfo) { |
109 for (var i = 0, routeInfo; routeInfo = this._routeInfo[i]; i++) { | 111 return routeInfo.model.__subscribe(this._evaluate.bind(this)); |
110 this._observer.addPath(routeInfo.model, 'active'); | 112 }.bind(this)); |
111 } | |
112 this._observer.open(this._evaluate.bind(this)); | |
113 }, | 113 }, |
114 | 114 |
115 _evaluate: function() { | 115 _evaluate: function() { |
116 var newIndex = -1; | 116 var newIndex = -1; |
117 var newRoute = null; | 117 var newRoute = null; |
118 var oldIndex = this.selectedIndex; | 118 var oldIndex = this.selectedIndex; |
119 | 119 |
120 for (var i = 0, routeInfo; routeInfo = this._routeInfo[i]; i++) { | 120 for (var i = 0, routeInfo; routeInfo = this._routeInfo[i]; i++) { |
121 if (routeInfo.model && routeInfo.model.active) { | 121 if (routeInfo.model && routeInfo.model.active) { |
122 newIndex = routeInfo.index; | 122 newIndex = routeInfo.index; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 } else { | 171 } else { |
172 // Equally specific; we fall back to the default (and hopefully | 172 // Equally specific; we fall back to the default (and hopefully |
173 // stable) sort order. | 173 // stable) sort order. |
174 return 0; | 174 return 0; |
175 } | 175 } |
176 } | 176 } |
177 }); | 177 }); |
178 }, | 178 }, |
179 | 179 |
180 }); | 180 }); |
OLD | NEW |