Skip to content

Commit 3f5fc72

Browse files
committed
Improve code style
1 parent f7748d4 commit 3f5fc72

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

JavaScript/1-imperative.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const STATE_EXIT = 3;
99

1010
let state = STATE_INIT;
1111

12-
(async () => {
12+
const main = async () => {
1313
for await (const chunk of process.stdin) {
1414
console.log({ chunk });
1515
switch (state) {
@@ -30,4 +30,6 @@ let state = STATE_INIT;
3030
process.exit(0);
3131
}
3232
}
33-
})();
33+
};
34+
35+
main();

JavaScript/3-class.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
const TIME_STEP = 500;
44

55
class StateMachine {
6+
static STATE = {
7+
INIT: 0,
8+
WORK: 1,
9+
FIN: 2,
10+
EXIT: 3,
11+
};
12+
613
constructor() {
714
this.state = StateMachine.STATE.INIT;
815
this.timer = setInterval(() => {
@@ -26,14 +33,8 @@ class StateMachine {
2633
}
2734
}
2835

29-
StateMachine.STATE = {
30-
INIT: 0,
31-
WORK: 1,
32-
FIN: 2,
33-
EXIT: 3,
34-
};
35-
3636
const sm = new StateMachine();
37+
3738
process.on('SIGINT', () => {
3839
sm.state = StateMachine.STATE.FIN;
3940
});

0 commit comments

Comments
 (0)