Skip to content

Commit c921cb8

Browse files
committed
style(useShell): code structure
1 parent 3f10681 commit c921cb8

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/common/useShell.ts

+9-11
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ type ShellEvent = {
1717
args: string[];
1818
};
1919

20-
21-
2220
const createId = () => Math.floor(Math.random() * 9999) + 1;
2321

2422
const useShell = () => {
23+
const on = (name: string, listener: (arg: any) => void) => {
24+
events.on(name, listener);
25+
};
26+
27+
const off = (name: string, listener: (arg: any) => void) => {
28+
events.off(name, listener);
29+
};
30+
2531
const send = (method: string, ...args: (string | number)[]) => {
2632
try {
2733
transport?.send(JSON.stringify({
@@ -31,19 +37,11 @@ const useShell = () => {
3137
method: 'onEvent',
3238
args: [method, ...args],
3339
}));
34-
} catch(e) {
40+
} catch (e) {
3541
console.error('Shell', 'Failed to send event', e);
3642
}
3743
};
3844

39-
const on = (name: string, listener: (arg: any) => void) => {
40-
events.on(name, listener);
41-
};
42-
43-
const off = (name: string, listener: (arg: any) => void) => {
44-
events.off(name, listener);
45-
};
46-
4745
useEffect(() => {
4846
if (!transport) return;
4947

0 commit comments

Comments
 (0)