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

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

Issue 2869273011: [MD Bookmarks] Convert bookmark list to iron-list. (Closed)
Patch Set: add comment, fix closure, rebase 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 /**
14 * A list of item ids wrapped in an Object. This is necessary because
15 * iron-list is unable to distinguish focusing index 6 from focusing id '6'
16 * so the item we supply to iron-list needs to be non-index-like.
17 * @private {Array<{id: string}>}
18 */
14 displayedList_: { 19 displayedList_: {
15 type: Array, 20 type: Array,
16 value: function() { 21 value: function() {
17 // Use an empty list during initialization so that the databinding to 22 // Use an empty list during initialization so that the databinding to
18 // hide #bookmarksCard takes effect. 23 // hide #bookmarksCard takes effect.
19 return []; 24 return [];
20 }, 25 },
21 }, 26 },
22 27
28 /** @private {Array<string>} */
29 displayedIds_: {
30 type: Array,
31 observer: 'onDisplayedIdsChanged_',
32 },
33
23 /** @private */ 34 /** @private */
24 searchTerm_: String, 35 searchTerm_: String,
25 }, 36 },
26 37
27 listeners: { 38 listeners: {
28 'click': 'deselectItems_', 39 'click': 'deselectItems_',
29 }, 40 },
30 41
31 attached: function() { 42 attached: function() {
32 this.watch('displayedList_', function(state) { 43 var list = /** @type {IronListElement} */ (this.$.bookmarksCard);
44 list.scrollTarget = this;
45
46 this.watch('displayedIds_', function(state) {
33 return bookmarks.util.getDisplayedList(state); 47 return bookmarks.util.getDisplayedList(state);
34 }); 48 });
35 this.watch('searchTerm_', function(state) { 49 this.watch('searchTerm_', function(state) {
36 return state.search.term; 50 return state.search.term;
37 }); 51 });
38 this.updateFromStore(); 52 this.updateFromStore();
39 }, 53 },
40 54
55 /** @return {HTMLElement} */
41 getDropTarget: function() { 56 getDropTarget: function() {
42 return this.$.message; 57 return this.$.message;
43 }, 58 },
44 59
60 /**
61 * Updates `displayedList_` using splices to be equivalent to `newValue`. This
62 * allows the iron-list to delete sublists of items which preserves scroll and
63 * focus on incremental update.
64 * @param {Array<string>} newValue
65 * @param {Array<string>} oldValue
66 */
67 onDisplayedIdsChanged_: function(newValue, oldValue) {
68 if (!oldValue) {
69 this.displayedList_ = this.displayedIds_.map(function(id) {
70 return {id: id};
71 });
72 } else {
73 var splices = Polymer.ArraySplice.calculateSplices(newValue, oldValue);
74 splices.forEach(function(splice) {
75 // TODO(calamity): Could use notifySplices to improve performance here.
76 var additions =
77 newValue.slice(splice.index, splice.index + splice.addedCount)
78 .map(function(id) {
79 return {id: id};
80 });
81 this.splice.apply(this, [
82 'displayedList_', splice.index, splice.removed.length
83 ].concat(additions));
84 }.bind(this));
85 }
86 },
87
45 /** @private */ 88 /** @private */
46 emptyListMessage_: function() { 89 emptyListMessage_: function() {
47 var emptyListMessage = this.searchTerm_ ? 'noSearchResults' : 'emptyList'; 90 var emptyListMessage = this.searchTerm_ ? 'noSearchResults' : 'emptyList';
48 return loadTimeData.getString(emptyListMessage); 91 return loadTimeData.getString(emptyListMessage);
49 }, 92 },
50 93
51 /** @private */ 94 /** @private */
52 isEmptyList_: function() { 95 isEmptyList_: function() {
53 return this.displayedList_.length == 0; 96 return this.displayedList_.length == 0;
54 }, 97 },
55 98
56 /** @private */ 99 /** @private */
57 deselectItems_: function() { 100 deselectItems_: function() {
58 this.dispatch(bookmarks.actions.deselectItems()); 101 this.dispatch(bookmarks.actions.deselectItems());
59 }, 102 },
60 }); 103 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/list.html ('k') | chrome/browser/resources/md_bookmarks/types.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698