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

Side by Side Diff: chrome/browser/resources/md_history/history_list_behavior.js

Issue 2597573002: MD History/Downloads: convert .bind(this) and function property values to use => (Closed)
Patch Set: Created 4 years 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 /** 5 /**
6 * @constructor 6 * @constructor
7 * @param {string} currentPath 7 * @param {string} currentPath
8 */ 8 */
9 var SelectionTreeNode = function(currentPath) { 9 var SelectionTreeNode = function(currentPath) {
10 /** @type {string} */ 10 /** @type {string} */
(...skipping 17 matching lines...) Expand all
28 28
29 /** @polymerBehavior */ 29 /** @polymerBehavior */
30 var HistoryListBehavior = { 30 var HistoryListBehavior = {
31 properties: { 31 properties: {
32 /** 32 /**
33 * Polymer paths to the history items contained in this list. 33 * Polymer paths to the history items contained in this list.
34 * @type {!Set<string>} selectedPaths 34 * @type {!Set<string>} selectedPaths
35 */ 35 */
36 selectedPaths: { 36 selectedPaths: {
37 type: Object, 37 type: Object,
38 value: /** @return {!Set<string>} */ function() { return new Set(); } 38 value: /** @return {!Set<string>} */ () => new Set(),
39 }, 39 },
40 40
41 lastSelectedPath: String, 41 lastSelectedPath: String,
42 }, 42 },
43 43
44 listeners: { 44 listeners: {
45 'history-checkbox-select': 'itemSelected_', 45 'history-checkbox-select': 'itemSelected_',
46 }, 46 },
47 47
48 /** 48 /**
(...skipping 23 matching lines...) Expand all
72 return ''; 72 return '';
73 73
74 var messageId = searchedTerm !== '' ? 'noSearchResults' : 'noResults'; 74 var messageId = searchedTerm !== '' ? 'noSearchResults' : 'noResults';
75 return loadTimeData.getString(messageId); 75 return loadTimeData.getString(messageId);
76 }, 76 },
77 77
78 /** 78 /**
79 * Deselect each item in |selectedPaths|. 79 * Deselect each item in |selectedPaths|.
80 */ 80 */
81 unselectAllItems: function() { 81 unselectAllItems: function() {
82 this.selectedPaths.forEach(function(path) { 82 this.selectedPaths.forEach(path => this.set(path + '.selected', false));
83 this.set(path + '.selected', false);
84 }.bind(this));
85
86 this.selectedPaths.clear(); 83 this.selectedPaths.clear();
87 }, 84 },
88 85
89 /** 86 /**
90 * Performs a request to the backend to delete all selected items. If 87 * Performs a request to the backend to delete all selected items. If
91 * successful, removes them from the view. Does not prompt the user before 88 * successful, removes them from the view. Does not prompt the user before
92 * deleting -- see <history-list-container> for a version of this method which 89 * deleting -- see <history-list-container> for a version of this method which
93 * does prompt. 90 * does prompt.
94 */ 91 */
95 deleteSelected: function() { 92 deleteSelected: function() {
96 var toBeRemoved = 93 var toBeRemoved =
97 Array.from(this.selectedPaths.values()).map(function(path) { 94 Array.from(this.selectedPaths.values()).map(path => this.get(path));
98 return this.get(path);
99 }.bind(this));
100 95
101 md_history.BrowserService.getInstance() 96 md_history.BrowserService.getInstance()
102 .deleteItems(toBeRemoved) 97 .deleteItems(toBeRemoved)
103 .then(function() { 98 .then(() => {
104 this.removeItemsByPath(Array.from(this.selectedPaths)); 99 this.removeItemsByPath(Array.from(this.selectedPaths));
105 this.fire('unselect-all'); 100 this.fire('unselect-all');
106 }.bind(this)); 101 });
107 }, 102 },
108 103
109 /** 104 /**
110 * Removes the history items in |paths|. Assumes paths are of a.0.b.0... 105 * Removes the history items in |paths|. Assumes paths are of a.0.b.0...
111 * structure. 106 * structure.
112 * 107 *
113 * We want to use notifySplices to update the arrays for performance reasons 108 * We want to use notifySplices to update the arrays for performance reasons
114 * which requires manually batching and sending the notifySplices for each 109 * which requires manually batching and sending the notifySplices for each
115 * level. To do this, we build a tree where each node is an array and then 110 * level. To do this, we build a tree where each node is an array and then
116 * depth traverse it to remove items. Each time a node has all children 111 * depth traverse it to remove items. Each time a node has all children
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 * they become empty. 159 * they become empty.
165 * @param {SelectionTreeNode} node 160 * @param {SelectionTreeNode} node
166 * @return {boolean} Whether this node's array should be deleted. 161 * @return {boolean} Whether this node's array should be deleted.
167 * @private 162 * @private
168 */ 163 */
169 removeItemsBeneathNode_: function(node) { 164 removeItemsBeneathNode_: function(node) {
170 var array = this.get(node.currentPath); 165 var array = this.get(node.currentPath);
171 var splices = []; 166 var splices = [];
172 167
173 node.indexes.sort(function(a, b) { return b - a; }); 168 node.indexes.sort(function(a, b) { return b - a; });
174 node.indexes.forEach(function(index) { 169 node.indexes.forEach(index => {
175 if (node.leaf || this.removeItemsBeneathNode_(node.children[index])) { 170 if (node.leaf || this.removeItemsBeneathNode_(node.children[index])) {
176 var item = array.splice(index, 1)[0]; 171 var item = array.splice(index, 1)[0];
177 splices.push({ 172 splices.push({
178 index: index, 173 index: index,
179 removed: [item], 174 removed: [item],
180 addedCount: 0, 175 addedCount: 0,
181 object: array, 176 object: array,
182 type: 'splice' 177 type: 'splice'
183 }); 178 });
184 } 179 }
185 }.bind(this)); 180 });
186 181
187 if (array.length == 0 && node.currentPath.indexOf('.') != -1) 182 if (array.length == 0 && node.currentPath.indexOf('.') != -1)
188 return true; 183 return true;
189 184
190 // notifySplices gives better performance than individually splicing as it 185 // notifySplices gives better performance than individually splicing as it
191 // batches all of the updates together. 186 // batches all of the updates together.
192 this.notifySplices(node.currentPath, splices); 187 this.notifySplices(node.currentPath, splices);
193 return false; 188 return false;
194 }, 189 },
195 190
(...skipping 21 matching lines...) Expand all
217 paths.push(itemArrayPath + '.' + i); 212 paths.push(itemArrayPath + '.' + i);
218 } 213 }
219 } 214 }
220 } 215 }
221 216
222 if (paths.length == 0) 217 if (paths.length == 0)
223 paths.push(item.path); 218 paths.push(item.path);
224 219
225 var selected = !this.selectedPaths.has(item.path); 220 var selected = !this.selectedPaths.has(item.path);
226 221
227 paths.forEach(function(path) { 222 paths.forEach(path => {
228 this.set(path + '.selected', selected); 223 this.set(path + '.selected', selected);
229 224
230 if (selected) { 225 if (selected) {
231 this.selectedPaths.add(path); 226 this.selectedPaths.add(path);
232 return; 227 return;
233 } 228 }
234 229
235 this.selectedPaths.delete(path); 230 this.selectedPaths.delete(path);
236 }.bind(this)); 231 });
237 232
238 this.lastSelectedPath = itemPath; 233 this.lastSelectedPath = itemPath;
239 }, 234 },
240 }; 235 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698