OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 /** | 6 /** |
7 * This element is a one way bound interface that routes the page URL to | 7 * This element is a one way bound interface that routes the page URL to |
8 * the searchTerm and selectedId. Clients must initialize themselves by | 8 * the searchTerm and selectedId. Clients must initialize themselves by |
9 * reading the router's fields after attach. | 9 * reading the router's fields after attach. |
10 */ | 10 */ |
(...skipping 12 matching lines...) Expand all Loading... | |
23 queryParams_: Object, | 23 queryParams_: Object, |
24 | 24 |
25 /** @private */ | 25 /** @private */ |
26 searchTerm_: String, | 26 searchTerm_: String, |
27 | 27 |
28 /** @private {?string} */ | 28 /** @private {?string} */ |
29 selectedId_: String, | 29 selectedId_: String, |
30 }, | 30 }, |
31 | 31 |
32 observers: [ | 32 observers: [ |
33 'onQueryChanged_(queryParams_.q)', | 33 'onQueryParamsChanged_(queryParams_)', |
34 'onFolderChanged_(queryParams_.id)', | |
35 'onStateChanged_(searchTerm_, selectedId_)', | 34 'onStateChanged_(searchTerm_, selectedId_)', |
36 ], | 35 ], |
37 | 36 |
38 attached: function() { | 37 attached: function() { |
39 this.watch('selectedId_', function(state) { | 38 this.watch('selectedId_', function(state) { |
40 return state.selectedFolder; | 39 return state.selectedFolder; |
41 }); | 40 }); |
42 this.watch('searchTerm_', function(state) { | 41 this.watch('searchTerm_', function(state) { |
43 return state.search.term; | 42 return state.search.term; |
44 }); | 43 }); |
45 this.updateFromStore(); | 44 this.updateFromStore(); |
46 }, | 45 }, |
47 | 46 |
48 /** @private */ | 47 /** @private */ |
49 onQueryChanged_: function() { | 48 onQueryParamsChanged_: function() { |
50 var searchTerm = this.queryParams_.q || ''; | 49 var searchTerm = this.queryParams_.q || ''; |
51 if (searchTerm && searchTerm != this.searchTerm_) { | 50 var selectedId = this.queryParams_.id; |
51 if (!selectedId && !searchTerm) | |
52 selectedId = BOOKMARKS_BAR_ID; | |
53 | |
54 if (searchTerm != (this.searchTerm_ || '')) { | |
calamity
2017/07/05 04:04:38
This is a wild line.
tsergeant
2017/07/05 07:37:36
Fixed. The OR case was only used during startup wh
| |
52 this.searchTerm_ = searchTerm; | 55 this.searchTerm_ = searchTerm; |
53 this.dispatch(bookmarks.actions.setSearchTerm(searchTerm)); | 56 this.dispatch(bookmarks.actions.setSearchTerm(searchTerm)); |
54 } | 57 } |
55 }, | |
56 | 58 |
57 /** @private */ | |
58 onFolderChanged_: function() { | |
59 var selectedId = this.queryParams_.id; | |
60 if (selectedId && selectedId != this.selectedId_) { | 59 if (selectedId && selectedId != this.selectedId_) { |
61 this.selectedId_ = selectedId; | 60 this.selectedId_ = selectedId; |
62 // Need to dispatch a deferred action so that during page load | 61 // Need to dispatch a deferred action so that during page load |
63 // `this.getState()` will only evaluate after the Store is initialized. | 62 // `this.getState()` will only evaluate after the Store is initialized. |
64 this.dispatchAsync(function(dispatch) { | 63 this.dispatchAsync(function(dispatch) { |
65 dispatch( | 64 dispatch( |
66 bookmarks.actions.selectFolder(selectedId, this.getState().nodes)); | 65 bookmarks.actions.selectFolder(selectedId, this.getState().nodes)); |
67 }.bind(this)); | 66 }.bind(this)); |
68 } | 67 } |
69 }, | 68 }, |
70 | 69 |
71 /** @private */ | 70 /** @private */ |
72 onStateChanged_: function() { | 71 onStateChanged_: function() { |
73 this.debounce('updateQueryParams', this.updateQueryParams_.bind(this)); | 72 this.debounce('updateQueryParams', this.updateQueryParams_.bind(this)); |
74 }, | 73 }, |
75 | 74 |
76 /** @private */ | 75 /** @private */ |
77 updateQueryParams_: function() { | 76 updateQueryParams_: function() { |
78 if (this.searchTerm_) | 77 if (this.searchTerm_) |
79 this.queryParams_ = {q: this.searchTerm_}; | 78 this.queryParams_ = {q: this.searchTerm_}; |
79 else if (this.selectedId_ != BOOKMARKS_BAR_ID) | |
80 this.queryParams_ = {id: this.selectedId_}; | |
80 else | 81 else |
81 this.queryParams_ = {id: this.selectedId_}; | 82 this.queryParams_ = {}; |
82 }, | 83 }, |
83 }); | 84 }); |
OLD | NEW |