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

Refactor DirectoryTree part 1 of 2

This is part of a reverted CL crrev.com/c/1300993, but this is the safe
part of it. I don't expect this to cause flakiness.

Change updateSubDirectories:
- use arrow function and const;
- change error callback calling style to match the same style used by
success callback (without if).
- change check from isFakeEntry to check for presence of the method
that's used "createReader".

Change the sorting to be an method, so it can be customized per
sub-class, later it will be used to sort My files to show Linux and Play
files at the bottom.

No changes in behaviour for users.

Change-Id: Ie8542464a360b5ed1970183dc888003119b423a9
Reviewed-on: https://chromium-review.googlesource.com/c/1313710
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604768}
parent 6c444ade
......@@ -482,6 +482,17 @@ DirectoryItem.prototype.handleClick = function(e) {
}
};
/**
* Default sorting for DirectoryItem sub-dirrectories.
* @param {!Array<!Entry>} entries Entries to be sorted.
* @returns {!Array<!Entry>}
*/
DirectoryItem.prototype.sortEntries = function(entries) {
entries.sort(util.compareName);
const filter = this.fileFilter_.filter.bind(this.fileFilter_);
return entries.filter(filter);
};
/**
* Retrieves the latest subdirectories and update them on the tree.
* @param {boolean} recursive True if the update is recursively.
......@@ -490,32 +501,23 @@ DirectoryItem.prototype.handleClick = function(e) {
*/
DirectoryItem.prototype.updateSubDirectories = function(
recursive, opt_successCallback, opt_errorCallback) {
if (!this.entry || util.isFakeEntry(this.entry)) {
if (opt_errorCallback)
opt_errorCallback();
if (!this.entry || this.entry.createReader === undefined) {
opt_errorCallback && opt_errorCallback();
return;
}
const sortEntries = (fileFilter, entries) => {
entries.sort(util.compareName);
return entries.filter(fileFilter.filter.bind(fileFilter));
};
const onSuccess = (entries) => {
this.entries_ = entries;
this.updateSubElementsFromList(recursive);
opt_successCallback && opt_successCallback();
};
const reader = this.entry.createReader();
const entries = [];
const readEntry = () => {
reader.readEntries((results) => {
if (!results.length) {
onSuccess(sortEntries(this.fileFilter_, entries));
onSuccess(this.sortEntries(entries));
return;
}
for (let i = 0; i < results.length; i++) {
const entry = results[i];
if (entry.isDirectory)
......
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