Skip to content

Commit 5c4660a

Browse files
authored
Refactor onDidChangeConfiguration handler in favor of listener pattern (#212)
* Refactor onDidChangeConfiguration handler in favor of listener pattern * Address comments in review
1 parent 1862284 commit 5c4660a

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/settings.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,26 @@ export class Settings {
1616
if (!e.affectsConfiguration("java.dependency")) {
1717
return;
1818
}
19-
const updatedConfig = workspace.getConfiguration("java.dependency");
19+
const oldConfig = this._dependencyConfig;
20+
this._dependencyConfig = workspace.getConfiguration("java.dependency");
2021
for (const listener of this._configurationListeners) {
21-
listener(updatedConfig, this._dependencyConfig);
22+
listener(this._dependencyConfig, oldConfig);
2223
}
23-
if (updatedConfig.showOutline !== this._dependencyConfig.showOutline
24-
|| updatedConfig.packagePresentation !== this._dependencyConfig.packagePresentation
25-
|| (updatedConfig.syncWithFolderExplorer !== this._dependencyConfig.syncWithFolderExplorer
24+
}));
25+
this.registerConfigurationListener((updatedConfig, oldConfig) => {
26+
if (updatedConfig.showOutline !== oldConfig.showOutline
27+
|| updatedConfig.packagePresentation !== oldConfig.packagePresentation
28+
|| (updatedConfig.syncWithFolderExplorer !== oldConfig.syncWithFolderExplorer
2629
&& updatedConfig.syncWithFolderExplorer)) {
27-
this._dependencyConfig = updatedConfig;
2830
commands.executeCommand(Commands.VIEW_PACKAGE_REFRESH);
29-
} else {
30-
if (updatedConfig.autoRefresh !== this._dependencyConfig.autoRefresh) {
31-
SyncHandler.updateFileWatcher(updatedConfig.autoRefresh);
32-
}
33-
this._dependencyConfig = updatedConfig;
3431
}
35-
}));
32+
});
33+
this.registerConfigurationListener((updatedConfig, oldConfig) => {
34+
if (updatedConfig.autoRefresh !== oldConfig.autoRefresh) {
35+
SyncHandler.updateFileWatcher(updatedConfig.autoRefresh);
36+
}
37+
});
38+
3639
SyncHandler.updateFileWatcher(Settings.autoRefresh());
3740

3841
context.subscriptions.push({ dispose: () => { this._configurationListeners = []; } });
@@ -100,4 +103,4 @@ enum PackagePresentation {
100103
Hierarchical = "hierarchical",
101104
}
102105

103-
type Listener = (updatedConfig: WorkspaceConfiguration, dependencyConfig: WorkspaceConfiguration) => void;
106+
type Listener = (updatedConfig: WorkspaceConfiguration, oldConfig: WorkspaceConfiguration) => void;

src/views/dependencyDataProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export class DependencyDataProvider implements TreeDataProvider<ExplorerNode> {
3232
instrumentOperation(Commands.VIEW_PACKAGE_OPEN_FILE, (_operationId, uri) => this.openFile(uri))));
3333
context.subscriptions.push(commands.registerCommand(Commands.VIEW_PACKAGE_OUTLINE,
3434
instrumentOperation(Commands.VIEW_PACKAGE_OUTLINE, (_operationId, uri, range) => this.goToOutline(uri, range))));
35-
Settings.registerConfigurationListener((updatedConfig, dependencyConfig) => {
36-
if (updatedConfig.refreshDelay !== dependencyConfig.refreshDelay) {
35+
Settings.registerConfigurationListener((updatedConfig, oldConfig) => {
36+
if (updatedConfig.refreshDelay !== oldConfig.refreshDelay) {
3737
this.setRefreshDelay(updatedConfig.refreshDelay);
3838
}
3939
});

0 commit comments

Comments
 (0)