| 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 24 matching lines...) Expand all Loading... |
| 35 'onStateChanged_(searchTerm_, selectedId_)', | 35 'onStateChanged_(searchTerm_, selectedId_)', |
| 36 ], | 36 ], |
| 37 | 37 |
| 38 attached: function() { | 38 attached: function() { |
| 39 this.watch('selectedId_', function(state) { | 39 this.watch('selectedId_', function(state) { |
| 40 return state.selectedFolder; | 40 return state.selectedFolder; |
| 41 }); | 41 }); |
| 42 this.watch('searchTerm_', function(state) { | 42 this.watch('searchTerm_', function(state) { |
| 43 return state.search.term; | 43 return state.search.term; |
| 44 }); | 44 }); |
| 45 this.updateFromStore(); |
| 45 }, | 46 }, |
| 46 | 47 |
| 47 /** @private */ | 48 /** @private */ |
| 48 onQueryChanged_: function() { | 49 onQueryChanged_: function() { |
| 49 var searchTerm = this.queryParams_.q || ''; | 50 var searchTerm = this.queryParams_.q || ''; |
| 50 if (searchTerm && searchTerm != this.searchTerm_) { | 51 if (searchTerm && searchTerm != this.searchTerm_) { |
| 51 this.searchTerm_ = searchTerm; | 52 this.searchTerm_ = searchTerm; |
| 52 this.dispatch(bookmarks.actions.setSearchTerm(searchTerm)); | 53 this.dispatch(bookmarks.actions.setSearchTerm(searchTerm)); |
| 53 } | 54 } |
| 54 }, | 55 }, |
| 55 | 56 |
| 56 /** @private */ | 57 /** @private */ |
| 57 onFolderChanged_: function() { | 58 onFolderChanged_: function() { |
| 58 var selectedId = this.queryParams_.id; | 59 var selectedId = this.queryParams_.id; |
| 59 if (selectedId && selectedId != this.selectedId_) { | 60 if (selectedId && selectedId != this.selectedId_) { |
| 60 this.selectedId_ = selectedId; | 61 this.selectedId_ = selectedId; |
| 61 this.dispatch(bookmarks.actions.selectFolder(selectedId)); | 62 // Need to dispatch a deferred action so that during page load |
| 63 // `this.getState()` will only evaluate after the Store is initialized. |
| 64 this.dispatchAsync(function(dispatch) { |
| 65 dispatch( |
| 66 bookmarks.actions.selectFolder(selectedId, this.getState().nodes)); |
| 67 }.bind(this)); |
| 62 } | 68 } |
| 63 }, | 69 }, |
| 64 | 70 |
| 65 /** @private */ | 71 /** @private */ |
| 66 onStateChanged_: function() { | 72 onStateChanged_: function() { |
| 67 this.debounce('updateQueryParams', this.updateQueryParams_.bind(this)); | 73 this.debounce('updateQueryParams', this.updateQueryParams_.bind(this)); |
| 68 }, | 74 }, |
| 69 | 75 |
| 70 /** @private */ | 76 /** @private */ |
| 71 updateQueryParams_: function() { | 77 updateQueryParams_: function() { |
| 72 if (this.searchTerm_) | 78 if (this.searchTerm_) |
| 73 this.queryParams_ = {q: this.searchTerm_}; | 79 this.queryParams_ = {q: this.searchTerm_}; |
| 74 else | 80 else |
| 75 this.queryParams_ = {id: this.selectedId_}; | 81 this.queryParams_ = {id: this.selectedId_}; |
| 76 }, | 82 }, |
| 77 }); | 83 }); |
| OLD | NEW |