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

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

Issue 2637023002: [MD Bookmarks] Add routing. (Closed)
Patch Set: Move store setup into replaceStore function. Created 3 years, 11 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
new file mode 100644
index 0000000000000000000000000000000000000000..ba224670599d2e6a757283b59715defdda5cbec0
--- /dev/null
+++ b/chrome/browser/resources/md_bookmarks/router.js
@@ -0,0 +1,54 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+Polymer({
+ /**
+ * This element is a one way bound interface that routes the page URL to
+ * the searchTerm and selectedId. Clients must initialize themselves by
+ * reading the router's fields after attach.
+ */
+ is: 'bookmarks-router',
+
+ properties: {
+ // Parameter q is routed to the searchTerm.
+ // Parameter id is routed to the selectedId.
+ queryParams_: Object,
+
+ searchTerm: {
+ type: String,
+ observer: 'onSearchTermChanged_',
+ },
+
+ /** @type {?string} */
+ selectedId: {
+ type: String,
+ observer: 'onSelectedChanged_',
calamity 2017/01/23 02:25:13 nit: onSelectedIdChanged_
+ },
+ },
+
+ observers: [
+ 'onQueryChanged_(queryParams_.*)',
+ ],
+
+ /** @private */
+ onQueryChanged_: function() {
+ this.searchTerm = this.queryParams_.q || '';
+ this.selectedId = this.queryParams_.id;
+
+ if (this.searchTerm)
+ this.fire('search-term-changed', this.searchTerm);
+ else
+ this.fire('selected-folder-changed', this.selectedId);
+ },
+
+ /** @private */
+ onSelectedChanged_: function() {
+ this.set('queryParams_.id', this.selectedId || null);
+ },
+
+ /** @private */
+ onSearchTermChanged_: function() {
+ this.set('queryParams_.q', this.searchTerm || null);
+ },
+});

Powered by Google App Engine
This is Rietveld 408576698