Skip to content

Commit de00662

Browse files
Copilotsawka
andcommitted
Refactor to reduce code duplication in controller resync methods
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
1 parent 9ce1e57 commit de00662

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

frontend/app/view/tsunami/tsunami.tsx

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,44 +81,30 @@ class TsunamiViewModel extends WebViewModel {
8181
prtn.catch((e) => console.log("error controller resync", e));
8282
}
8383

84-
restartController() {
84+
private doControllerResync(forceRestart: boolean, logContext: string) {
8585
if (globalStore.get(this.isRestarting)) {
8686
return;
8787
}
8888
this.triggerRestartAtom();
8989
const prtn = RpcApi.ControllerResyncCommand(TabRpcClient, {
9090
tabid: globalStore.get(atoms.staticTabId),
9191
blockid: this.blockId,
92-
forcerestart: false,
92+
forcerestart: forceRestart,
9393
});
94-
prtn.catch((e) => console.log("error controller resync (restart)", e));
94+
prtn.catch((e) => console.log(`error controller resync (${logContext})`, e));
95+
}
96+
97+
restartController() {
98+
this.doControllerResync(false, "restart");
9599
}
96100

97101
restartAndForceRebuild() {
98-
if (globalStore.get(this.isRestarting)) {
99-
return;
100-
}
101-
this.triggerRestartAtom();
102-
const prtn = RpcApi.ControllerResyncCommand(TabRpcClient, {
103-
tabid: globalStore.get(atoms.staticTabId),
104-
blockid: this.blockId,
105-
forcerestart: true,
106-
});
107-
prtn.catch((e) => console.log("error controller resync (force rebuild)", e));
102+
this.doControllerResync(true, "force rebuild");
108103
}
109104

110105
forceRestartController() {
111106
// Keep this for backward compatibility with the Start button
112-
if (globalStore.get(this.isRestarting)) {
113-
return;
114-
}
115-
this.triggerRestartAtom();
116-
const prtn = RpcApi.ControllerResyncCommand(TabRpcClient, {
117-
tabid: globalStore.get(atoms.staticTabId),
118-
blockid: this.blockId,
119-
forcerestart: true,
120-
});
121-
prtn.catch((e) => console.log("error controller resync (force restart)", e));
107+
this.doControllerResync(true, "force restart");
122108
}
123109

124110
setAppMeta(meta: TsunamiAppMeta) {

0 commit comments

Comments
 (0)