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

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

Issue 2795623002: MD Bookmarks: Handle bookmark creation (Closed)
Patch Set: Update test Created 3 years, 8 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 /** 5 /**
6 * @fileoverview Listener functions which translate events from the 6 * @fileoverview Listener functions which translate events from the
7 * chrome.bookmarks API into actions to modify the local page state. 7 * chrome.bookmarks API into actions to modify the local page state.
8 */ 8 */
9 9
10 cr.define('bookmarks.ApiListener', function() { 10 cr.define('bookmarks.ApiListener', function() {
11 /** @param {Action} action */ 11 /** @param {Action} action */
12 function dispatch(action) { 12 function dispatch(action) {
13 bookmarks.Store.getInstance().handleAction(action); 13 bookmarks.Store.getInstance().handleAction(action);
14 } 14 }
15 15
16 /** 16 /**
17 * @param {string} id 17 * @param {string} id
18 * @param {{title: string, url: (string|undefined)}} changeInfo 18 * @param {{title: string, url: (string|undefined)}} changeInfo
19 */ 19 */
20 function onBookmarkChanged(id, changeInfo) { 20 function onBookmarkChanged(id, changeInfo) {
21 dispatch(bookmarks.actions.editBookmark(id, changeInfo)); 21 dispatch(bookmarks.actions.editBookmark(id, changeInfo));
22 } 22 }
23 23
24 /** 24 /**
25 * @param {string} id 25 * @param {string} id
26 * @param {BookmarkTreeNode} treeNode
27 */
28 function onBookmarkCreated(id, treeNode) {
29 dispatch(bookmarks.actions.createBookmark(id, treeNode));
30 }
31
32 /**
33 * @param {string} id
26 * @param {{parentId: string, index: number}} removeInfo 34 * @param {{parentId: string, index: number}} removeInfo
27 */ 35 */
28 function onBookmarkRemoved(id, removeInfo) { 36 function onBookmarkRemoved(id, removeInfo) {
29 dispatch(bookmarks.actions.removeBookmark( 37 dispatch(bookmarks.actions.removeBookmark(
30 id, removeInfo.parentId, removeInfo.index)); 38 id, removeInfo.parentId, removeInfo.index));
31 } 39 }
32 40
33 /** 41 /**
34 * @param {string} id 42 * @param {string} id
35 * @param {{ 43 * @param {{
36 * parentId: string, 44 * parentId: string,
37 * index: number, 45 * index: number,
38 * oldParentId: string, 46 * oldParentId: string,
39 * oldIndex: number 47 * oldIndex: number
40 * }} moveInfo 48 * }} moveInfo
41 */ 49 */
42 function onBookmarkMoved(id, moveInfo) { 50 function onBookmarkMoved(id, moveInfo) {
43 dispatch(bookmarks.actions.moveBookmark( 51 dispatch(bookmarks.actions.moveBookmark(
44 id, moveInfo.parentId, moveInfo.index, moveInfo.oldParentId, 52 id, moveInfo.parentId, moveInfo.index, moveInfo.oldParentId,
45 moveInfo.oldIndex)); 53 moveInfo.oldIndex));
46 } 54 }
47 55
56 /**
57 * Pauses the Created handler during an import. The imported nodes will all be
58 * loaded at once when the import is finished.
59 */
48 function onImportBegan() { 60 function onImportBegan() {
49 // TODO(rongjie): pause onCreated once this event is used. 61 chrome.bookmarks.onCreated.removeListener(onBookmarkCreated);
50 } 62 }
51 63
52 function onImportEnded() { 64 function onImportEnded() {
53 chrome.bookmarks.getTree(function(results) { 65 chrome.bookmarks.getTree(function(results) {
54 dispatch(bookmarks.actions.refreshNodes( 66 dispatch(bookmarks.actions.refreshNodes(
55 bookmarks.util.normalizeNodes(results[0]))); 67 bookmarks.util.normalizeNodes(results[0])));
56 }); 68 });
69 chrome.bookmarks.onCreated.addListener(onBookmarkCreated);
57 } 70 }
58 71
59 function init() { 72 function init() {
60 chrome.bookmarks.onChanged.addListener(onBookmarkChanged); 73 chrome.bookmarks.onChanged.addListener(onBookmarkChanged);
74 chrome.bookmarks.onCreated.addListener(onBookmarkCreated);
61 chrome.bookmarks.onMoved.addListener(onBookmarkMoved); 75 chrome.bookmarks.onMoved.addListener(onBookmarkMoved);
62 chrome.bookmarks.onRemoved.addListener(onBookmarkRemoved); 76 chrome.bookmarks.onRemoved.addListener(onBookmarkRemoved);
63 chrome.bookmarks.onImportBegan.addListener(onImportBegan); 77 chrome.bookmarks.onImportBegan.addListener(onImportBegan);
64 chrome.bookmarks.onImportEnded.addListener(onImportEnded); 78 chrome.bookmarks.onImportEnded.addListener(onImportEnded);
65 } 79 }
66 80
67 return { 81 return {
68 init: init, 82 init: init,
69 }; 83 };
70 }); 84 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/actions.js ('k') | chrome/browser/resources/md_bookmarks/reducers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698