| 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: [ | 8 behaviors: [ |
| 9 bookmarks.StoreClient, | 9 bookmarks.StoreClient, |
| 10 ], | 10 ], |
| 11 | 11 |
| 12 properties: { |
| 13 /** @private */ |
| 14 searchTerm_: { |
| 15 type: String, |
| 16 observer: 'searchTermChanged_', |
| 17 }, |
| 18 }, |
| 19 |
| 12 /** @override */ | 20 /** @override */ |
| 13 attached: function() { | 21 attached: function() { |
| 22 this.watch('searchTerm_', function(store) { |
| 23 return store.search.term; |
| 24 }); |
| 25 |
| 14 chrome.bookmarks.getTree(function(results) { | 26 chrome.bookmarks.getTree(function(results) { |
| 15 var nodeList = bookmarks.util.normalizeNodes(results[0]); | 27 var nodeList = bookmarks.util.normalizeNodes(results[0]); |
| 16 var initialState = bookmarks.util.createEmptyState(); | 28 var initialState = bookmarks.util.createEmptyState(); |
| 17 initialState.nodes = nodeList; | 29 initialState.nodes = nodeList; |
| 18 initialState.selectedFolder = nodeList['0'].children[0]; | 30 initialState.selectedFolder = nodeList['0'].children[0]; |
| 19 | 31 |
| 20 bookmarks.Store.getInstance().init(initialState); | 32 bookmarks.Store.getInstance().init(initialState); |
| 21 bookmarks.ApiListener.init(); | 33 bookmarks.ApiListener.init(); |
| 22 }.bind(this)); | 34 }.bind(this)); |
| 23 }, | 35 }, |
| 36 |
| 37 searchTermChanged_: function() { |
| 38 if (!this.searchTerm_) |
| 39 return; |
| 40 |
| 41 chrome.bookmarks.search(this.searchTerm_, function(results) { |
| 42 var ids = results.map(function(node) { |
| 43 return node.id; |
| 44 }); |
| 45 this.dispatch(bookmarks.actions.setSearchResults(ids)); |
| 46 }.bind(this)); |
| 47 }, |
| 24 }); | 48 }); |
| OLD | NEW |