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

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

Issue 2869273011: [MD Bookmarks] Convert bookmark list to iron-list. (Closed)
Patch Set: address comments Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 is: 'bookmarks-list', 6 is: 'bookmarks-list',
7 7
8 behaviors: [ 8 behaviors: [
9 bookmarks.StoreClient, 9 bookmarks.StoreClient,
10 ], 10 ],
11 11
12 properties: { 12 properties: {
13 /** @private {Array<string>} */ 13 /** @private {Array<{id: string}>} */
14 displayedList_: { 14 displayedList_: {
15 type: Array, 15 type: Array,
16 // Use an empty list during initialization so that the databinding to
17 // hide #bookmarksCard takes effect.
16 value: function() { 18 value: function() {
17 // Use an empty list during initialization so that the databinding to
18 // hide #bookmarksCard takes effect.
19 return []; 19 return [];
20 }, 20 },
21 }, 21 },
22 22
23 /** @private {Array<string>} */
24 displayedIds_: {
25 type: Array,
26 observer: 'onDisplayedIdsChanged_',
27 },
28
23 /** @private */ 29 /** @private */
24 searchTerm_: String, 30 searchTerm_: String,
25 }, 31 },
26 32
27 listeners: { 33 listeners: {
28 'click': 'deselectItems_', 34 'click': 'deselectItems_',
29 }, 35 },
30 36
31 attached: function() { 37 attached: function() {
32 this.watch('displayedList_', function(state) { 38 var list = /** @type {IronListElement} */ (this.$.bookmarksCard);
39 list.scrollTarget = this;
40
41 this.watch('displayedIds_', function(state) {
33 return bookmarks.util.getDisplayedList(state); 42 return bookmarks.util.getDisplayedList(state);
34 }); 43 });
35 this.watch('searchTerm_', function(state) { 44 this.watch('searchTerm_', function(state) {
36 return state.search.term; 45 return state.search.term;
37 }); 46 });
38 this.updateFromStore(); 47 this.updateFromStore();
39 }, 48 },
40 49
41 getDropTarget: function() { 50 getDropTarget: function() {
42 return this.$.message; 51 return this.$.message;
43 }, 52 },
44 53
54 onDisplayedIdsChanged_: function(newValue, oldValue) {
tsergeant 2017/05/16 03:41:51 Comment here with why all this is necessary/useful
calamity 2017/05/17 03:28:27 Done.
55 if (!oldValue) {
56 this.displayedList_ = this.displayedIds_.map(function(id) {
57 return {id: id};
58 });
59 } else {
60 var splices = Polymer.ArraySplice.calculateSplices(newValue, oldValue);
61 splices.forEach(function(splice) {
62 // TODO(calamity): Could use notifySplices to improve performance here.
63 var additions =
64 newValue.slice(splice.index, splice.index + splice.addedCount)
65 .map(function(id) {
66 return {id: id};
67 });
68 this.splice(
69 'displayedList_', splice.index, splice.removed.length,
70 ...additions);
tsergeant 2017/05/16 03:41:51 Check if uglify errors when parsing this file (I s
calamity 2017/05/17 03:28:27 Done.
71 }.bind(this));
72 }
73 },
74
45 /** @private */ 75 /** @private */
46 emptyListMessage_: function() { 76 emptyListMessage_: function() {
47 var emptyListMessage = this.searchTerm_ ? 'noSearchResults' : 'emptyList'; 77 var emptyListMessage = this.searchTerm_ ? 'noSearchResults' : 'emptyList';
48 return loadTimeData.getString(emptyListMessage); 78 return loadTimeData.getString(emptyListMessage);
49 }, 79 },
50 80
51 /** @private */ 81 /** @private */
52 isEmptyList_: function() { 82 isEmptyList_: function() {
53 return this.displayedList_.length == 0; 83 return this.displayedList_.length == 0;
54 }, 84 },
55 85
56 /** @private */ 86 /** @private */
57 deselectItems_: function() { 87 deselectItems_: function() {
58 this.dispatch(bookmarks.actions.deselectItems()); 88 this.dispatch(bookmarks.actions.deselectItems());
59 }, 89 },
60 }); 90 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/list.html ('k') | chrome/test/data/webui/md_bookmarks/list_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698