Skip to content

Commit b2a8ec4

Browse files
author
John Preston
committed
Decouple UI update from internal state
Previously the Paredit StatusBar's toggleBarItem was being updated throughout multiple setters. Now we refactor the UI update into a single method and remove the internal `_enabled` state which is now unused.
1 parent dccd384 commit b2a8ec4

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

src/paredit/statusbar.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import * as paredit from './extension';
55

66
export class StatusBar {
77

8-
private _enabled: Boolean;
98
private _visible: Boolean;
109
private _keyMap: String;
1110

@@ -16,56 +15,42 @@ export class StatusBar {
1615
this._toggleBarItem.text = "(λ)";
1716
this._toggleBarItem.tooltip = "";
1817
this._toggleBarItem.command = 'paredit.togglemode';
19-
this._enabled = false;
2018
this._visible = false;
2119
this.keyMap = keymap;
2220

2321
paredit.onPareditKeyMapChanged((keymap) => {
2422
this.keyMap = keymap;
25-
})
23+
})
2624
}
2725

2826
get keyMap() {
2927
return this._keyMap;
3028
}
3129

3230
set keyMap(keymap: String) {
33-
34-
switch (keymap.trim().toLowerCase()) {
31+
this._keyMap = keymap;
32+
this.updateUIState();
33+
}
34+
35+
updateUIState() {
36+
switch (this.keyMap.trim().toLowerCase()) {
3537
case 'original':
36-
this._keyMap = 'original';
37-
this.enabled = true;
3838
this.visible = true;
3939
this._toggleBarItem.text = "(λ)";
40-
this._toggleBarItem.tooltip = "Toggle to strict Mode"
40+
this._toggleBarItem.tooltip = "Toggle to strict Mode";
41+
this._toggleBarItem.color = undefined;
4142
break;
4243
case 'strict':
43-
this._keyMap = 'strict';
44-
this.enabled = true;
4544
this.visible = true;
4645
this._toggleBarItem.text = "[λ]";
47-
this._toggleBarItem.tooltip = "Toggle to original Mode"
46+
this._toggleBarItem.tooltip = "Toggle to original Mode";
47+
this._toggleBarItem.color = undefined;
4848
break;
4949
default:
50-
this._keyMap = 'none';
51-
this.enabled = false;
5250
this.visible = true;
5351
this._toggleBarItem.text = "λ";
5452
this._toggleBarItem.tooltip = "Calva Paredit Keymap is set to none, Toggle to Strict Mode is Disabled"
55-
}
56-
}
57-
58-
get enabled() {
59-
return this._enabled;
60-
}
61-
62-
set enabled(value: Boolean) {
63-
this._enabled = value;
64-
65-
if (this._enabled) {
66-
this._toggleBarItem.color = undefined;
67-
} else {
68-
this._toggleBarItem.color = statusbar.color.inactive;
53+
this._toggleBarItem.color = statusbar.color.inactive;
6954
}
7055
}
7156

@@ -84,4 +69,4 @@ export class StatusBar {
8469
dispose() {
8570
this._toggleBarItem.dispose();
8671
}
87-
}
72+
}

0 commit comments

Comments
 (0)