Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: chrome/browser/resources/md_bookmarks/router.js

Issue 2745993002: MD Bookmarks: Update URL router to work in new data binding system (Closed)
Patch Set: calamity@ review Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 */
11 is: 'bookmarks-router', 11 is: 'bookmarks-router',
12 12
13 behaviors: [
14 bookmarks.StoreClient,
15 ],
16
13 properties: { 17 properties: {
14 // Parameter q is routed to the searchTerm. 18 /**
15 // Parameter id is routed to the selectedId. 19 * Parameter q is routed to the searchTerm.
20 * Parameter id is routed to the selectedId.
21 * @private
22 */
16 queryParams_: Object, 23 queryParams_: Object,
17 24
18 searchTerm: { 25 /** @private */
19 type: String, 26 searchTerm_: String,
20 observer: 'onSearchTermChanged_',
21 },
22 27
23 /** @type {?string} */ 28 /** @private {?string} */
24 selectedId: { 29 selectedId_: String,
25 type: String,
26 observer: 'onSelectedIdChanged_',
27 },
28 }, 30 },
29 31
30 observers: [ 32 observers: [
31 'onQueryChanged_(queryParams_.*)', 33 'onQueryChanged_(queryParams_.q)',
34 'onFolderChanged_(queryParams_.id)',
35 'onStateChanged_(searchTerm_, selectedId_)',
32 ], 36 ],
33 37
38 attached: function() {
39 this.watch('selectedId_', function(state) {
40 return state.selectedFolder;
41 });
42 this.watch('searchTerm_', function(state) {
43 return state.search.term;
44 });
45 },
46
34 /** @private */ 47 /** @private */
35 onQueryChanged_: function() { 48 onQueryChanged_: function() {
36 this.searchTerm = this.queryParams_.q || ''; 49 var searchTerm = this.queryParams_.q || '';
37 this.selectedId = this.queryParams_.id; 50 if (searchTerm && searchTerm != this.searchTerm_) {
38 51 this.searchTerm_ = searchTerm;
39 if (this.searchTerm) 52 this.dispatch(bookmarks.actions.setSearchTerm(searchTerm));
40 this.fire('search-term-changed', this.searchTerm); 53 }
41 else
42 this.fire('selected-folder-changed', this.selectedId);
43 }, 54 },
44 55
45 /** @private */ 56 /** @private */
46 onSelectedIdChanged_: function() { 57 onFolderChanged_: function() {
47 this.set('queryParams_.id', this.selectedId || null); 58 var selectedId = this.queryParams_.id;
59 if (selectedId && selectedId != this.selectedId_) {
60 this.selectedId_ = selectedId;
61 this.dispatch(bookmarks.actions.selectFolder(selectedId));
62 }
48 }, 63 },
49 64
50 /** @private */ 65 /** @private */
51 onSearchTermChanged_: function() { 66 onStateChanged_: function() {
52 this.set('queryParams_.q', this.searchTerm || null); 67 this.debounce('updateQueryParams', this.updateQueryParams_.bind(this));
68 },
69
70 /** @private */
71 updateQueryParams_: function() {
72 if (this.searchTerm_)
73 this.queryParams_ = {q: this.searchTerm_};
74 else
75 this.queryParams_ = {id: this.selectedId_};
53 }, 76 },
54 }); 77 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/router.html ('k') | chrome/browser/resources/md_bookmarks/toolbar.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698