Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 57b90c6

Browse files
committed
Merge pull request #9735 from adobe/dangoor/true-refresh
Make the Refresh File Tree command clear caches
2 parents 7e5dff3 + c6a2f46 commit 57b90c6

File tree

3 files changed

+23
-50
lines changed

3 files changed

+23
-50
lines changed

src/filesystem/FileSystem.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,16 @@ define(function (require, exports, module) {
816816
}
817817
}
818818
};
819-
819+
820+
/**
821+
* Clears all cached content. Because of the performance implications of this, this should only be used if
822+
* there is a suspicion that the file system has not been updated through the normal file watchers
823+
* mechanism.
824+
*/
825+
FileSystem.prototype.clearAllCaches = function () {
826+
this._handleExternalChange(null);
827+
};
828+
820829
/**
821830
* Start watching a filesystem root entry.
822831
*
@@ -965,6 +974,7 @@ define(function (require, exports, module) {
965974
exports.showSaveDialog = _wrap(FileSystem.prototype.showSaveDialog);
966975
exports.watch = _wrap(FileSystem.prototype.watch);
967976
exports.unwatch = _wrap(FileSystem.prototype.unwatch);
977+
exports.clearAllCaches = _wrap(FileSystem.prototype.clearAllCaches);
968978

969979
// Static public utility methods
970980
exports.isAbsolutePath = FileSystem.isAbsolutePath;

src/project/ProjectManager.js

+9-46
Original file line numberDiff line numberDiff line change
@@ -920,21 +920,6 @@ define(function (require, exports, module) {
920920
return result.promise();
921921
}
922922

923-
/**
924-
* @private
925-
* @type {?$.Promise} Resolves when the currently running instance of
926-
* _refreshFileTreeInternal completes, or null if there is no currently
927-
* running instance.
928-
*/
929-
var _refreshFileTreePromise = null;
930-
931-
/**
932-
* @type {boolean} If refreshFileTree is called before _refreshFileTreePromise
933-
* has resolved then _refreshPending is set, which indicates that
934-
* refreshFileTree should be called again once the promise resolves.
935-
*/
936-
var _refreshPending = false;
937-
938923
/**
939924
* @const
940925
* @private
@@ -944,38 +929,16 @@ define(function (require, exports, module) {
944929

945930
/**
946931
* Refresh the project's file tree, maintaining the current selection.
947-
*
948-
* @return {$.Promise} A promise object that will be resolved when the
949-
* project tree is reloaded, or rejected if the project path
950-
* fails to reload. If the previous selected entry is not found,
951-
* the promise is still resolved.
932+
*
933+
* Note that the original implementation of this returned a promise to be resolved when the refresh is complete.
934+
* That use is deprecated and `refreshFileTree` is now a "fire and forget" kind of function.
952935
*/
953-
function refreshFileTree() {
954-
if (!_refreshFileTreePromise) {
955-
var internalRefreshPromise = model.refresh(),
956-
deferred = new $.Deferred();
957-
958-
_refreshFileTreePromise = deferred.promise();
959-
960-
_refreshFileTreePromise.always(function () {
961-
_refreshFileTreePromise = null;
962-
963-
if (_refreshPending) {
964-
_refreshPending = false;
965-
refreshFileTree();
966-
}
967-
});
968-
969-
// Wait at least one second before resolving the promise
970-
window.setTimeout(function () {
971-
internalRefreshPromise.then(deferred.resolve, deferred.reject);
972-
}, _refreshDelay);
973-
} else {
974-
_refreshPending = true;
975-
}
976-
977-
return _refreshFileTreePromise;
978-
}
936+
var refreshFileTree = function refreshFileTree() {
937+
FileSystem.clearAllCaches();
938+
return new $.Deferred().resolve().promise();
939+
};
940+
941+
refreshFileTree = _.debounce(refreshFileTree, _refreshDelay);
979942

980943
/**
981944
* Expands tree nodes to show the given file or folder and selects it. Silently no-ops if the

src/project/ProjectModel.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1075,9 +1075,9 @@ define(function (require, exports, module) {
10751075
});
10761076
}
10771077
};
1078-
1078+
10791079
/**
1080-
* Refreshes the contents of the tree.
1080+
* Clears caches and refreshes the contents of the tree.
10811081
*
10821082
* @return {$.Promise} resolved when the tree has been refreshed
10831083
*/
@@ -1088,7 +1088,7 @@ define(function (require, exports, module) {
10881088
selections = this._selections,
10891089
viewModel = this._viewModel,
10901090
deferred = new $.Deferred();
1091-
1091+
10921092
this.setProjectRoot(projectRoot).then(function () {
10931093
self.reopenNodes(openNodes).then(function () {
10941094
if (selections.selected) {

0 commit comments

Comments
 (0)