Commit a18491f1 authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Convert directory_tree.js to arrow function using lebab

Command used:
$ lebab --replace \
    ui/file_manager/file_manager/foreground/js/ui/directory_tree.js \
    --transform arrow

Lebab: https://github.com/lebab/lebab

No change in behaviour.

Bug: 778674
Change-Id: Ie67f01d023c1c762c5e7b4fdba9c7df5b0debb89
Reviewed-on: https://chromium-review.googlesource.com/c/1298526Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602966}
parent be2b45dd
...@@ -374,8 +374,7 @@ DirectoryItem.prototype.searchAndSelectByEntry = function(entry) { ...@@ -374,8 +374,7 @@ DirectoryItem.prototype.searchAndSelectByEntry = function(entry) {
* @param {boolean=} opt_unused Unused. * @param {boolean=} opt_unused Unused.
* @override * @override
*/ */
DirectoryItem.prototype.scrollIntoViewIfNeeded = function(opt_unused) { DirectoryItem.prototype.scrollIntoViewIfNeeded = function(opt_unused) {};
};
/** /**
* Removes the child node, but without selecting the parent item, to avoid * Removes the child node, but without selecting the parent item, to avoid
...@@ -414,16 +413,16 @@ DirectoryItem.prototype.onExpand_ = function(e) { ...@@ -414,16 +413,16 @@ DirectoryItem.prototype.onExpand_ = function(e) {
} }
this.updateSubDirectories( this.updateSubDirectories(
true /* recursive */, true /* recursive */,
function() { () => {
if (!this.insideDrive) if (!this.insideDrive)
return; return;
this.parentTree_.metadataModel_.get( this.parentTree_.metadataModel_.get(
this.entries_, this.entries_,
constants.LIST_CONTAINER_METADATA_PREFETCH_PROPERTY_NAMES); constants.LIST_CONTAINER_METADATA_PREFETCH_PROPERTY_NAMES);
}.bind(this), },
function() { () => {
this.expanded = false; this.expanded = false;
}.bind(this)); });
e.stopPropagation(); e.stopPropagation();
}; };
...@@ -433,7 +432,7 @@ DirectoryItem.prototype.onExpand_ = function(e) { ...@@ -433,7 +432,7 @@ DirectoryItem.prototype.onExpand_ = function(e) {
* @param {DirectoryItem} parentItem The parent item to start searching from. * @param {DirectoryItem} parentItem The parent item to start searching from.
* @return {!Array<Entry>} * @return {!Array<Entry>}
*/ */
let getVisibleChildEntries = function(parentItem) { let getVisibleChildEntries = (parentItem) => {
if (parentItem.expanded == false) { if (parentItem.expanded == false) {
return [parentItem.entry]; return [parentItem.entry];
} }
...@@ -513,34 +512,34 @@ DirectoryItem.prototype.updateSubDirectories = function( ...@@ -513,34 +512,34 @@ DirectoryItem.prototype.updateSubDirectories = function(
return; return;
} }
var sortEntries = function(fileFilter, entries) { const sortEntries = (fileFilter, entries) => {
entries.sort(util.compareName); entries.sort(util.compareName);
return entries.filter(fileFilter.filter.bind(fileFilter)); return entries.filter(fileFilter.filter.bind(fileFilter));
}; };
var onSuccess = function(entries) { const onSuccess = (entries) => {
this.entries_ = entries; this.entries_ = entries;
this.updateSubElementsFromList(recursive); this.updateSubElementsFromList(recursive);
opt_successCallback && opt_successCallback(); opt_successCallback && opt_successCallback();
}.bind(this); };
var reader = this.entry.createReader(); const reader = this.entry.createReader();
var entries = []; const entries = [];
var readEntry = function() { const readEntry = () => {
reader.readEntries(function(results) { reader.readEntries((results) => {
if (!results.length) { if (!results.length) {
onSuccess(sortEntries(this.fileFilter_, entries)); onSuccess(sortEntries(this.fileFilter_, entries));
return; return;
} }
for (var i = 0; i < results.length; i++) { for (let i = 0; i < results.length; i++) {
var entry = results[i]; const entry = results[i];
if (entry.isDirectory) if (entry.isDirectory)
entries.push(entry); entries.push(entry);
} }
readEntry(); readEntry();
}.bind(this)); });
}.bind(this); };
readEntry(); readEntry();
}; };
...@@ -573,8 +572,7 @@ DirectoryItem.prototype.updateItemByEntry = function(changedDirectoryEntry) { ...@@ -573,8 +572,7 @@ DirectoryItem.prototype.updateItemByEntry = function(changedDirectoryEntry) {
/** /**
* Update the icon based on whether the folder is shared on Drive. * Update the icon based on whether the folder is shared on Drive.
*/ */
DirectoryItem.prototype.updateSharedStatusIcon = function() { DirectoryItem.prototype.updateSharedStatusIcon = function() {};
};
/** /**
* Select the item corresponding to the given {@code entry}. * Select the item corresponding to the given {@code entry}.
...@@ -833,7 +831,7 @@ function VolumeItem(modelItem, tree) { ...@@ -833,7 +831,7 @@ function VolumeItem(modelItem, tree) {
item.setContextMenu_(tree.contextMenuForRootItems); item.setContextMenu_(tree.contextMenuForRootItems);
// Populate children of this volume using resolved display root. // Populate children of this volume using resolved display root.
item.volumeInfo_.resolveDisplayRoot(function(displayRoot) { item.volumeInfo_.resolveDisplayRoot((displayRoot) => {
item.updateSubDirectories(false /* recursive */); item.updateSubDirectories(false /* recursive */);
}); });
...@@ -895,7 +893,7 @@ VolumeItem.prototype.updateSubDirectories = function( ...@@ -895,7 +893,7 @@ VolumeItem.prototype.updateSubDirectories = function(
*/ */
VolumeItem.prototype.activate = function() { VolumeItem.prototype.activate = function() {
var directoryModel = this.parentTree_.directoryModel; var directoryModel = this.parentTree_.directoryModel;
var onEntryResolved = function(entry) { var onEntryResolved = (entry) => {
// Changes directory to the model item's root directory if needed. // Changes directory to the model item's root directory if needed.
if (!util.isSameEntry(directoryModel.getCurrentDirEntry(), entry)) { if (!util.isSameEntry(directoryModel.getCurrentDirEntry(), entry)) {
metrics.recordUserAction('FolderShortcut.Navigate'); metrics.recordUserAction('FolderShortcut.Navigate');
...@@ -904,14 +902,14 @@ VolumeItem.prototype.activate = function() { ...@@ -904,14 +902,14 @@ VolumeItem.prototype.activate = function() {
// In case of failure in resolveDisplayRoot() in the volume's constructor, // In case of failure in resolveDisplayRoot() in the volume's constructor,
// update the volume's children here. // update the volume's children here.
this.updateSubDirectories(false); this.updateSubDirectories(false);
}.bind(this); };
this.volumeInfo_.resolveDisplayRoot( this.volumeInfo_.resolveDisplayRoot(
onEntryResolved, onEntryResolved,
function() { () => {
// Error, the display root is not available. It may happen on Drive. // Error, the display root is not available. It may happen on Drive.
this.parentTree_.dataModel.onItemNotFoundError(this.modelItem); this.parentTree_.dataModel.onItemNotFoundError(this.modelItem);
}.bind(this)); });
}; };
/** /**
...@@ -949,23 +947,23 @@ VolumeItem.prototype.setupIcon_ = function(icon, volumeInfo) { ...@@ -949,23 +947,23 @@ VolumeItem.prototype.setupIcon_ = function(icon, volumeInfo) {
VolumeItem.prototype.setupEjectButton_ = function(rowElement) { VolumeItem.prototype.setupEjectButton_ = function(rowElement) {
var ejectButton = cr.doc.createElement('button'); var ejectButton = cr.doc.createElement('button');
// Block other mouse handlers. // Block other mouse handlers.
ejectButton.addEventListener('mouseup', function(event) { ejectButton.addEventListener('mouseup', (event) => {
event.stopPropagation(); event.stopPropagation();
}); });
ejectButton.addEventListener('mousedown', function(event) { ejectButton.addEventListener('mousedown', (event) => {
event.stopPropagation(); event.stopPropagation();
}); });
ejectButton.className = 'root-eject'; ejectButton.className = 'root-eject';
ejectButton.setAttribute('aria-label', str('UNMOUNT_DEVICE_BUTTON_LABEL')); ejectButton.setAttribute('aria-label', str('UNMOUNT_DEVICE_BUTTON_LABEL'));
ejectButton.setAttribute('tabindex', '0'); ejectButton.setAttribute('tabindex', '0');
ejectButton.addEventListener('click', function(event) { ejectButton.addEventListener('click', (event) => {
event.stopPropagation(); event.stopPropagation();
var unmountCommand = cr.doc.querySelector('command#unmount'); var unmountCommand = cr.doc.querySelector('command#unmount');
// Let's make sure 'canExecute' state of the command is properly set for // Let's make sure 'canExecute' state of the command is properly set for
// the root before executing it. // the root before executing it.
unmountCommand.canExecuteChange(this); unmountCommand.canExecuteChange(this);
unmountCommand.execute(this); unmountCommand.execute(this);
}.bind(this)); });
rowElement.appendChild(ejectButton); rowElement.appendChild(ejectButton);
// Add paper-ripple effect on the eject button. // Add paper-ripple effect on the eject button.
...@@ -1038,9 +1036,9 @@ DriveVolumeItem.prototype.handleClick = function(e) { ...@@ -1038,9 +1036,9 @@ DriveVolumeItem.prototype.handleClick = function(e) {
if (!e.target.classList.contains('expand-icon')) { if (!e.target.classList.contains('expand-icon')) {
// If the Drive volume is clicked, select one of the children instead of // If the Drive volume is clicked, select one of the children instead of
// this item itself. // this item itself.
this.volumeInfo_.resolveDisplayRoot(function(displayRoot) { this.volumeInfo_.resolveDisplayRoot((displayRoot) => {
this.searchAndSelectByEntry(displayRoot); this.searchAndSelectByEntry(displayRoot);
}.bind(this)); });
} }
DirectoryItemTreeBaseMethods.recordUMASelectedEntry.call( DirectoryItemTreeBaseMethods.recordUMASelectedEntry.call(
...@@ -1061,7 +1059,7 @@ DriveVolumeItem.prototype.handleClick = function(e) { ...@@ -1061,7 +1059,7 @@ DriveVolumeItem.prototype.handleClick = function(e) {
* @private * @private
*/ */
DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() { DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() {
return new Promise(resolve => { return new Promise((resolve) => {
const teamDriveGrandRoot = this.volumeInfo_.teamDriveDisplayRoot; const teamDriveGrandRoot = this.volumeInfo_.teamDriveDisplayRoot;
if (!teamDriveGrandRoot) { if (!teamDriveGrandRoot) {
// Team Drive is disabled. // Team Drive is disabled.
...@@ -1079,7 +1077,7 @@ DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() { ...@@ -1079,7 +1077,7 @@ DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() {
} }
const reader = teamDriveGrandRoot.createReader(); const reader = teamDriveGrandRoot.createReader();
reader.readEntries(results => { reader.readEntries((results) => {
metrics.recordSmallCount('TeamDrivesCount', results.length); metrics.recordSmallCount('TeamDrivesCount', results.length);
// Only create grand root if there is at least 1 child/result. // Only create grand root if there is at least 1 child/result.
if (results.length) { if (results.length) {
...@@ -1127,7 +1125,7 @@ DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() { ...@@ -1127,7 +1125,7 @@ DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() {
* @private * @private
*/ */
DriveVolumeItem.prototype.createComputersGrandRoot_ = function() { DriveVolumeItem.prototype.createComputersGrandRoot_ = function() {
return new Promise(resolve => { return new Promise((resolve) => {
const computerGrandRoot = this.volumeInfo_.computersDisplayRoot; const computerGrandRoot = this.volumeInfo_.computersDisplayRoot;
if (!computerGrandRoot) { if (!computerGrandRoot) {
// Computer is disabled. // Computer is disabled.
...@@ -1210,7 +1208,7 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) { ...@@ -1210,7 +1208,7 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) {
for (var key in this.volumeInfo_.fakeEntries) for (var key in this.volumeInfo_.fakeEntries)
fakeEntries.push(this.volumeInfo_.fakeEntries[key]); fakeEntries.push(this.volumeInfo_.fakeEntries[key]);
// This list is sorted by URL on purpose. // This list is sorted by URL on purpose.
fakeEntries.sort(function(a, b) { fakeEntries.sort((a, b) => {
if (a.toURL() === b.toURL()) if (a.toURL() === b.toURL())
return 0; return 0;
return b.toURL() > a.toURL() ? 1 : -1; return b.toURL() > a.toURL() ? 1 : -1;
...@@ -1251,7 +1249,7 @@ DriveVolumeItem.prototype.updateItemByEntry = function(changedDirectoryEntry) { ...@@ -1251,7 +1249,7 @@ DriveVolumeItem.prototype.updateItemByEntry = function(changedDirectoryEntry) {
// If Team Drive grand root has been removed and we receive an update for an // If Team Drive grand root has been removed and we receive an update for an
// team drive, we need to create the Team Drive grand root. // team drive, we need to create the Team Drive grand root.
if (isTeamDriveChild) { if (isTeamDriveChild) {
this.createTeamDrivesGrandRoot_().then(teamDriveGrandRootItem => { this.createTeamDrivesGrandRoot_().then((teamDriveGrandRootItem) => {
if (teamDriveGrandRootItem) if (teamDriveGrandRootItem)
teamDriveGrandRootItem.updateItemByEntry(changedDirectoryEntry); teamDriveGrandRootItem.updateItemByEntry(changedDirectoryEntry);
}); });
...@@ -1262,7 +1260,7 @@ DriveVolumeItem.prototype.updateItemByEntry = function(changedDirectoryEntry) { ...@@ -1262,7 +1260,7 @@ DriveVolumeItem.prototype.updateItemByEntry = function(changedDirectoryEntry) {
// If Computers grand root has been removed and we receive an update for an // If Computers grand root has been removed and we receive an update for an
// computer, we need to create the Computers grand root. // computer, we need to create the Computers grand root.
if (isComputersChild) { if (isComputersChild) {
this.createComputersGrandRoot_().then(computersGrandRootItem => { this.createComputersGrandRoot_().then((computersGrandRootItem) => {
if (computersGrandRootItem) if (computersGrandRootItem)
computersGrandRootItem.updateItemByEntry(changedDirectoryEntry); computersGrandRootItem.updateItemByEntry(changedDirectoryEntry);
}); });
...@@ -1420,25 +1418,25 @@ ShortcutItem.prototype.setContextMenu_ = function(menu) { ...@@ -1420,25 +1418,25 @@ ShortcutItem.prototype.setContextMenu_ = function(menu) {
*/ */
ShortcutItem.prototype.activate = function() { ShortcutItem.prototype.activate = function() {
var directoryModel = this.parentTree_.directoryModel; var directoryModel = this.parentTree_.directoryModel;
var onEntryResolved = function(entry) { var onEntryResolved = (entry) => {
// Changes directory to the model item's root directory if needed. // Changes directory to the model item's root directory if needed.
if (!util.isSameEntry(directoryModel.getCurrentDirEntry(), entry)) { if (!util.isSameEntry(directoryModel.getCurrentDirEntry(), entry)) {
metrics.recordUserAction('FolderShortcut.Navigate'); metrics.recordUserAction('FolderShortcut.Navigate');
directoryModel.changeDirectoryEntry(entry); directoryModel.changeDirectoryEntry(entry);
} }
}.bind(this); };
// For shortcuts we already have an Entry, but it has to be resolved again // For shortcuts we already have an Entry, but it has to be resolved again
// in case, it points to a non-existing directory. // in case, it points to a non-existing directory.
window.webkitResolveLocalFileSystemURL( window.webkitResolveLocalFileSystemURL(
this.entry.toURL(), this.entry.toURL(),
onEntryResolved, onEntryResolved,
function() { () => {
// Error, the entry can't be re-resolved. It may happen for shortcuts // Error, the entry can't be re-resolved. It may happen for shortcuts
// which targets got removed after resolving the Entry during // which targets got removed after resolving the Entry during
// initialization. // initialization.
this.parentTree_.dataModel.onItemNotFoundError(this.modelItem); this.parentTree_.dataModel.onItemNotFoundError(this.modelItem);
}.bind(this)); });
}; };
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -1882,10 +1880,10 @@ DirectoryTree.prototype.onEntriesChanged_ = function(event) { ...@@ -1882,10 +1880,10 @@ DirectoryTree.prototype.onEntriesChanged_ = function(event) {
Promise.all( Promise.all(
directories.map((directory) => directories.map((directory) =>
new Promise(directory.getParent.bind(directory)))) new Promise(directory.getParent.bind(directory))))
.then(function(parentDirectories) { .then((parentDirectories) => {
parentDirectories.forEach((parentDirectory) => parentDirectories.forEach((parentDirectory) =>
this.updateTreeByEntry_(parentDirectory)); this.updateTreeByEntry_(parentDirectory));
}.bind(this)); });
break; break;
case util.EntryChangedKind.DELETED: case util.EntryChangedKind.DELETED:
directories.forEach((directory) => this.updateTreeByEntry_(directory)); directories.forEach((directory) => this.updateTreeByEntry_(directory));
...@@ -1912,12 +1910,12 @@ DirectoryTree.prototype.selectByEntry = function(entry) { ...@@ -1912,12 +1910,12 @@ DirectoryTree.prototype.selectByEntry = function(entry) {
var volumeInfo = this.volumeManager_.getVolumeInfo(entry); var volumeInfo = this.volumeManager_.getVolumeInfo(entry);
if (!volumeInfo) if (!volumeInfo)
return; return;
volumeInfo.resolveDisplayRoot(function() { volumeInfo.resolveDisplayRoot(() => {
if (this.sequence_ !== currentSequence) if (this.sequence_ !== currentSequence)
return; return;
if (!this.searchAndSelectByEntry(entry)) if (!this.searchAndSelectByEntry(entry))
this.selectedItem = null; this.selectedItem = null;
}.bind(this)); });
}; };
/** /**
...@@ -1989,7 +1987,7 @@ DirectoryTree.prototype.onDirectoryContentChanged_ = function(event) { ...@@ -1989,7 +1987,7 @@ DirectoryTree.prototype.onDirectoryContentChanged_ = function(event) {
*/ */
DirectoryTree.prototype.updateTreeByEntry_ = function(entry) { DirectoryTree.prototype.updateTreeByEntry_ = function(entry) {
entry.getDirectory(entry.fullPath, {create: false}, entry.getDirectory(entry.fullPath, {create: false},
function() { () => {
// If entry exists. // If entry exists.
// e.g. /a/b is deleted while watching /a. // e.g. /a/b is deleted while watching /a.
for (var i = 0; i < this.items.length; i++) { for (var i = 0; i < this.items.length; i++) {
...@@ -1997,15 +1995,15 @@ DirectoryTree.prototype.updateTreeByEntry_ = function(entry) { ...@@ -1997,15 +1995,15 @@ DirectoryTree.prototype.updateTreeByEntry_ = function(entry) {
this.items[i] instanceof EntryListItem) this.items[i] instanceof EntryListItem)
this.items[i].updateItemByEntry(entry); this.items[i].updateItemByEntry(entry);
} }
}.bind(this), },
function() { () => {
// If entry does not exist, try to get parent and update the subtree by // If entry does not exist, try to get parent and update the subtree by
// it. // it.
// e.g. /a/b is deleted while watching /a/b. Try to update /a in this // e.g. /a/b is deleted while watching /a/b. Try to update /a in this
// case. // case.
entry.getParent(function(parentEntry) { entry.getParent((parentEntry) => {
this.updateTreeByEntry_(parentEntry); this.updateTreeByEntry_(parentEntry);
}.bind(this), function(error) { }, (error) => {
// If it fails to get parent, update the subtree by volume. // If it fails to get parent, update the subtree by volume.
// e.g. /a/b is deleted while watching /a/b/c. getParent of /a/b/c // e.g. /a/b is deleted while watching /a/b/c. getParent of /a/b/c
// fails in this case. We falls back to volume update. // fails in this case. We falls back to volume update.
...@@ -2022,8 +2020,8 @@ DirectoryTree.prototype.updateTreeByEntry_ = function(entry) { ...@@ -2022,8 +2020,8 @@ DirectoryTree.prototype.updateTreeByEntry_ = function(entry) {
this.items[i].updateSubDirectories(true /* recursive */); this.items[i].updateSubDirectories(true /* recursive */);
} }
} }
}.bind(this)); });
}.bind(this)); });
}; };
/** /**
...@@ -2040,7 +2038,7 @@ DirectoryTree.prototype.onCurrentDirectoryChanged_ = function(event) { ...@@ -2040,7 +2038,7 @@ DirectoryTree.prototype.onCurrentDirectoryChanged_ = function(event) {
* @private * @private
*/ */
DirectoryTree.prototype.onListContentChanged_ = function() { DirectoryTree.prototype.onListContentChanged_ = function() {
this.updateSubDirectories(false, function() { this.updateSubDirectories(false, () => {
// If no item is selected now, try to select the item corresponding to // If no item is selected now, try to select the item corresponding to
// current directory because the current directory might have been populated // current directory because the current directory might have been populated
// in this tree in previous updateSubDirectories(). // in this tree in previous updateSubDirectories().
...@@ -2049,7 +2047,7 @@ DirectoryTree.prototype.onListContentChanged_ = function() { ...@@ -2049,7 +2047,7 @@ DirectoryTree.prototype.onListContentChanged_ = function() {
if (currentDir) if (currentDir)
this.selectByEntry(currentDir); this.selectByEntry(currentDir);
} }
}.bind(this)); });
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment