| 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: 'bookmarks-app', | 6 is: 'bookmarks-app', |
| 7 | 7 |
| 8 behaviors: [ |
| 9 bookmarks.StoreClient, |
| 10 ], |
| 11 |
| 8 properties: { | 12 properties: { |
| 9 selectedId: String, | 13 searchTerm: { |
| 10 | 14 type: String, |
| 11 /** @type {BookmarkTreeNode} */ | 15 observer: 'searchTermChanged_', |
| 12 rootNode: Object, | 16 }, |
| 13 | |
| 14 searchTerm: String, | |
| 15 | |
| 16 /** @type {Array<BookmarkTreeNode>} */ | |
| 17 displayedList: Array, | |
| 18 }, | 17 }, |
| 19 | 18 |
| 20 /** @override */ | 19 /** @override */ |
| 21 attached: function() { | 20 attached: function() { |
| 22 /** @type {BookmarksStore} */ (this.$$('bookmarks-store')) | 21 this.observe('searchTerm', function(store) { |
| 23 .initializeStore(); | 22 return store.search.term; |
| 23 }); |
| 24 |
| 25 chrome.bookmarks.getTree(function(results) { |
| 26 var nodeList = bookmarks.util.normalizeNodes(results[0]); |
| 27 var initialState = bookmarks.util.createEmptyState(); |
| 28 initialState.nodes = nodeList; |
| 29 initialState.selectedFolder = nodeList['0'].children[0]; |
| 30 |
| 31 // TODO(tsergeant): The below ends up slightly duplicating logic from |
| 32 // elsewhere. Consider trying to use actions/reducers to simplify this. |
| 33 var router = this.$.router; |
| 34 if (router.searchTerm) { |
| 35 initialState.selectedFolder = null; |
| 36 initialState.search.term = router.searchTerm; |
| 37 initialState.search.inProgress = true; |
| 38 } else if (router.selectedId) { |
| 39 initialState.selectedFolder = router.selectedId; |
| 40 } |
| 41 |
| 42 bookmarks.Store.getInstance().init(initialState); |
| 43 bookmarks.ApiListener.init(); |
| 44 }.bind(this)); |
| 45 }, |
| 46 |
| 47 searchTermChanged_: function() { |
| 48 if (this.searchTerm) { |
| 49 chrome.bookmarks.search(this.searchTerm, function(results) { |
| 50 this.dispatch(bookmarks.actions.setSearchResults(results)); |
| 51 }.bind(this)); |
| 52 } |
| 24 }, | 53 }, |
| 25 }); | 54 }); |
| OLD | NEW |