Skip to content

Commit

Permalink
Simpler implementation of refreshFileTree that does a full refresh.
Browse files Browse the repository at this point in the history
  • Loading branch information
dangoor committed Oct 30, 2014
1 parent 8331ec7 commit c6a2f46
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 62 deletions.
4 changes: 1 addition & 3 deletions src/filesystem/FileSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,7 @@ define(function (require, exports, module) {
* mechanism.
*/
FileSystem.prototype.clearAllCaches = function () {
this._index.visitAll(function (entry) {
entry._clearCachedData(true);
});
this._handleExternalChange(null);
};

/**
Expand Down
55 changes: 9 additions & 46 deletions src/project/ProjectManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -920,21 +920,6 @@ define(function (require, exports, module) {
return result.promise();
}

/**
* @private
* @type {?$.Promise} Resolves when the currently running instance of
* _refreshFileTreeInternal completes, or null if there is no currently
* running instance.
*/
var _refreshFileTreePromise = null;

/**
* @type {boolean} If refreshFileTree is called before _refreshFileTreePromise
* has resolved then _refreshPending is set, which indicates that
* refreshFileTree should be called again once the promise resolves.
*/
var _refreshPending = false;

/**
* @const
* @private
Expand All @@ -944,38 +929,16 @@ define(function (require, exports, module) {

/**
* Refresh the project's file tree, maintaining the current selection.
*
* @return {$.Promise} A promise object that will be resolved when the
* project tree is reloaded, or rejected if the project path
* fails to reload. If the previous selected entry is not found,
* the promise is still resolved.
*
* Note that the original implementation of this returned a promise to be resolved when the refresh is complete.
* That use is deprecated and `refreshFileTree` is now a "fire and forget" kind of function.
*/
function refreshFileTree() {
if (!_refreshFileTreePromise) {
var internalRefreshPromise = model.refresh(),
deferred = new $.Deferred();

_refreshFileTreePromise = deferred.promise();

_refreshFileTreePromise.always(function () {
_refreshFileTreePromise = null;

if (_refreshPending) {
_refreshPending = false;
refreshFileTree();
}
});

// Wait at least one second before resolving the promise
window.setTimeout(function () {
internalRefreshPromise.then(deferred.resolve, deferred.reject);
}, _refreshDelay);
} else {
_refreshPending = true;
}

return _refreshFileTreePromise;
}
var refreshFileTree = function refreshFileTree() {
FileSystem.clearAllCaches();
return new $.Deferred().resolve().promise();
};

refreshFileTree = _.debounce(refreshFileTree, _refreshDelay);

/**
* Expands tree nodes to show the given file or folder and selects it. Silently no-ops if the
Expand Down
11 changes: 0 additions & 11 deletions src/project/ProjectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,16 +1076,6 @@ define(function (require, exports, module) {
}
};

/**
* @private
*
* Clear all caches associated with the project.
*/
ProjectModel.prototype._clearAllCaches = function () {
this._resetCache();
FileSystem.clearAllCaches();
};

/**
* Clears caches and refreshes the contents of the tree.
*
Expand All @@ -1099,7 +1089,6 @@ define(function (require, exports, module) {
viewModel = this._viewModel,
deferred = new $.Deferred();

this._clearAllCaches();
this.setProjectRoot(projectRoot).then(function () {
self.reopenNodes(openNodes).then(function () {
if (selections.selected) {
Expand Down
2 changes: 0 additions & 2 deletions test/spec/ProjectModel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,6 @@ define(function (require, exports, module) {

it("should refresh the whole tree", function () {
var oldTree;
spyOn(model, "_clearAllCaches");
waitsForDone(model.reopenNodes(data.nodesByDepth));
runs(function () {
model.setSelected("/foo/subdir1/subsubdir/interior.txt");
Expand All @@ -1103,7 +1102,6 @@ define(function (require, exports, module) {
expect(vm._treeData.getIn(["subdir1", "children", "subsubdir", "children", "newInterior.txt"])).toBeDefined();
expect(vm._treeData.getIn(["subdir1", "children", "subsubdir", "children", "interior.txt"])).toBeUndefined();
expect(vm._treeData.getIn(["subdir3", "children", "higher.txt", "context"])).toBe(true);
expect(model._clearAllCaches).toHaveBeenCalled();
});
});
});
Expand Down

0 comments on commit c6a2f46

Please sign in to comment.