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

Unified Diff: chrome/browser/resources/md_bookmarks/router.js

Issue 2704983002: MD Bookmarks: Proof-of-concept reimplementation of data storage/binding layer (Closed)
Patch Set: Add doc comments Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_bookmarks/router.js
diff --git a/chrome/browser/resources/md_bookmarks/router.js b/chrome/browser/resources/md_bookmarks/router.js
index 38b16f1602b66411ddf12a73668bcad0cd2e54e0..ac0634c239684e2e0ecdbd80400f1966e91875d6 100644
--- a/chrome/browser/resources/md_bookmarks/router.js
+++ b/chrome/browser/resources/md_bookmarks/router.js
@@ -10,6 +10,10 @@ Polymer({
*/
is: 'bookmarks-router',
+ behaviors: [
+ bookmarks.StoreClient,
+ ],
+
properties: {
// Parameter q is routed to the searchTerm.
// Parameter id is routed to the selectedId.
@@ -17,38 +21,57 @@ Polymer({
searchTerm: {
type: String,
- observer: 'onSearchTermChanged_',
},
/** @type {?string} */
selectedId: {
type: String,
- observer: 'onSelectedIdChanged_',
},
},
observers: [
- 'onQueryChanged_(queryParams_.*)',
+ 'onQueryChanged_(queryParams_.q)',
+ 'onFolderChanged_(queryParams_.id)',
+ 'onStateChanged_(searchTerm, selectedId)',
],
+ attached: function() {
+ this.observe('selectedId', function(state) {
+ return state.selectedFolder;
+ });
+ this.observe('searchTerm', function(state) {
+ return state.search.term;
+ });
+ },
+
/** @private */
onQueryChanged_: function() {
- this.searchTerm = this.queryParams_.q || '';
- this.selectedId = this.queryParams_.id;
+ var searchTerm = this.queryParams_.q || '';
+ if (searchTerm && searchTerm != this.searchTerm) {
+ this.searchTerm = searchTerm;
+ this.dispatch(bookmarks.actions.setSearchTerm(searchTerm));
+ }
+ },
- if (this.searchTerm)
- this.fire('search-term-changed', this.searchTerm);
- else
- this.fire('selected-folder-changed', this.selectedId);
+ /** @private */
+ onFolderChanged_: function() {
+ var selectedId = this.queryParams_.id;
+ if (selectedId && selectedId != this.selectedId) {
+ this.selectedId = selectedId;
+ this.dispatch(bookmarks.actions.selectFolder(selectedId));
+ }
},
/** @private */
- onSelectedIdChanged_: function() {
- this.set('queryParams_.id', this.selectedId || null);
+ onStateChanged_: function() {
+ this.debounce('updateQueryParams', this.updateQueryParams_.bind(this));
},
/** @private */
- onSearchTermChanged_: function() {
- this.set('queryParams_.q', this.searchTerm || null);
+ updateQueryParams_: function() {
+ if (this.searchTerm)
+ this.queryParams_ = {q: this.searchTerm};
+ else
+ this.queryParams_ = {id: this.selectedId};
},
});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/router.html ('k') | chrome/browser/resources/md_bookmarks/sidebar.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698