| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 Polymer({ | 5 Polymer({ |
| 6 is: 'history-router', | 6 is: 'history-router', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 selectedPage: { | 9 selectedPage: { |
| 10 type: String, | 10 type: String, |
| 11 observer: 'serializePath_', | 11 observer: 'serializePath_', |
| 12 notify: true, | 12 notify: true, |
| 13 }, | 13 }, |
| 14 | 14 |
| 15 /** @type {QueryState} */ | |
| 16 queryState: { | |
| 17 type: Object, | |
| 18 notify: true, | |
| 19 value: function() { | |
| 20 // TODO(tsergeant: Move this initialization into query-manager. | |
| 21 return { | |
| 22 // Whether the most recent query was incremental. | |
| 23 incremental: false, | |
| 24 // A query is initiated by page load. | |
| 25 querying: true, | |
| 26 queryingDisabled: false, | |
| 27 _range: HistoryRange.ALL_TIME, | |
| 28 searchTerm: '', | |
| 29 groupedOffset: 0, | |
| 30 | |
| 31 set range(val) { | |
| 32 this._range = Number(val); | |
| 33 }, | |
| 34 get range() { | |
| 35 return this._range; | |
| 36 }, | |
| 37 }; | |
| 38 }, | |
| 39 }, | |
| 40 | |
| 41 path_: { | 15 path_: { |
| 42 type: String, | 16 type: String, |
| 43 observer: 'pathChanged_', | 17 observer: 'pathChanged_', |
| 44 }, | 18 }, |
| 45 | 19 |
| 20 /** @type {QueryState} */ |
| 21 queryState: Object, |
| 22 |
| 46 queryParams_: Object, | 23 queryParams_: Object, |
| 47 }, | 24 }, |
| 48 | 25 |
| 49 observers: [ | 26 observers: [ |
| 50 'queryParamsChanged_(queryParams_.*)', | 27 'queryParamsChanged_(queryParams_.*)', |
| 51 'searchTermChanged_(queryState.searchTerm)', | 28 'searchTermChanged_(queryState.searchTerm)', |
| 52 ], | 29 ], |
| 53 | 30 |
| 54 /** @override */ | 31 /** @override */ |
| 55 attached: function() { | 32 attached: function() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 67 }, | 44 }, |
| 68 | 45 |
| 69 /** @private */ | 46 /** @private */ |
| 70 pathChanged_: function() { | 47 pathChanged_: function() { |
| 71 var sections = this.path_.substr(1).split('/'); | 48 var sections = this.path_.substr(1).split('/'); |
| 72 this.selectedPage = sections[0] || 'history'; | 49 this.selectedPage = sections[0] || 'history'; |
| 73 }, | 50 }, |
| 74 | 51 |
| 75 /** @private */ | 52 /** @private */ |
| 76 queryParamsChanged_: function() { | 53 queryParamsChanged_: function() { |
| 77 this.set('queryState.searchTerm', this.queryParams_.q || ''); | 54 this.fire('change-query', {search: this.queryParams_.q || ''}); |
| 78 }, | 55 }, |
| 79 | 56 |
| 80 /** @private */ | 57 /** @private */ |
| 81 searchTermChanged_: function() { | 58 searchTermChanged_: function() { |
| 82 this.set('queryParams_.q', this.queryState.searchTerm || null); | 59 this.set('queryParams_.q', this.queryState.searchTerm || null); |
| 83 }, | 60 }, |
| 84 }); | 61 }); |
| OLD | NEW |