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

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

Issue 2735953002: MD Bookmarks: Integrate new data store with UI elements (Closed)
Patch Set: More tweaks 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_bookmarks/api_listener.js
diff --git a/chrome/browser/resources/md_bookmarks/api_listener.js b/chrome/browser/resources/md_bookmarks/api_listener.js
new file mode 100644
index 0000000000000000000000000000000000000000..7edb24bdc700593ae4678612e661a4713b6134c3
--- /dev/null
+++ b/chrome/browser/resources/md_bookmarks/api_listener.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.
+
+/**
+ * @fileoverview Listener functions which translate events from the
+ * chrome.bookmarks API into actions to modify the local page state.
+ */
+
+cr.define('bookmarks.ApiListener', function() {
+ /** @param {Action} action */
+ function dispatch(action) {
+ bookmarks.Store.getInstance().handleAction(action);
+ }
+
+ /**
+ * @param {string} id
+ * @param {{title: string, url: (string|undefined)}} changeInfo
+ */
+ function onBookmarkChanged(id, changeInfo) {
+ dispatch(bookmarks.actions.editBookmark(id, changeInfo));
+ }
+
+ /**
+ * @param {string} id
+ * @param {{parentId: string, index: number}} removeInfo
+ */
+ function onBookmarkRemoved(id, removeInfo) {
+ dispatch(bookmarks.actions.removeBookmark(
+ id, removeInfo.parentId, removeInfo.index));
calamity 2017/03/09 04:58:57 I don't feel strongly, but it feels weird that thi
tsergeant 2017/03/09 06:27:54 I thought the same way at first, but now I think i
+ }
+
+ function onImportBegan() {
+ // TODO(rongjie): pause onCreated once this event is used.
+ }
+
+ function onImportEnded() {
+ chrome.bookmarks.getTree(function(results) {
+ dispatch(bookmarks.actions.refreshNodes(
+ bookmarks.util.normalizeNodes(results[0])));
+ });
+ }
+
+ function init() {
+ chrome.bookmarks.onChanged.addListener(onBookmarkChanged);
+ chrome.bookmarks.onRemoved.addListener(onBookmarkRemoved);
+ chrome.bookmarks.onImportBegan.addListener(onImportBegan);
+ chrome.bookmarks.onImportEnded.addListener(onImportEnded);
calamity 2017/03/09 04:58:57 *Golf clap*
tsergeant 2017/03/09 06:27:54 Name your methods very carefully in order to prese
+ }
+
+ return {
+ init: init,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698