Skip to content

Commit acb07c6

Browse files
dev-dongwoncrongro
authored andcommitted
Step5-3 : TUNA & YM 리뷰 내용 반영 (#136)
* fix : resolve conflict * fix : 리뷰 내용 추가 REAMD.md * Rename : lowerCase to uppercase * Rename : cmd to command * Refactor : 배열을 변수에 할당 후 네이밍 * Refactor : remove result variable * Refactor : object to destructuring * Fix : else if to else * Refactor : modified try block * feat : create getLogObj method * Refactor : class to Object * Fix : this.utils to Utils object * Fix : remove duplicated method * fix : fix the indent
1 parent 430a7d3 commit acb07c6

File tree

8 files changed

+500
-2
lines changed

8 files changed

+500
-2
lines changed

README.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
1-
# todo
2-
레벨2
1+
## STEP5-3 : TUNA & YM 리뷰 내용 반영
2+
3+
#
4+
#### 1. comment : 전체코드의 들여쓰기가 너무 깊은데요? 좋은 indent 가 무엇인지 한번찾아볼래요?
5+
6+
- 전체 코드 indent 수정 : tab 인덴트를 space * 4 로 수정
7+
- 원인 : pair를 위해 구름 ide에서 작업 중, local으로 옮기면서 indent 오반영
8+
9+
원래 ide의 설정은 tab이 space * 4 의 indent로 설정되어 있습니다.
10+
앞으로 들여쓰기가 올바르게 되어있는지, 불편하지 않은지 신경쓰도록 하겠습니다
11+
12+
#
13+
14+
#### 2. comment : 주석이 필요한.. arguments.length 로 구별하는 방식을 어떻게 개선할 수 있을까요?
15+
16+
- 리뷰 이전
17+
```javascript
18+
if (argument.length === 3) // updaste
19+
...
20+
} else if (arguments.length === 2) { // add, delete
21+
```
22+
23+
- 리뷰 이후 : 의미가 불분명해 주석이 필요했던 if statement 수정
24+
25+
```javascript
26+
if (command === 'update') {
27+
...
28+
} else if (command === 'add' || command === 'delete') {
29+
...
30+
}
31+
```
32+
33+
#
34+
35+
#### 3. utils 클래스의 deepCopy 메서드의 이해
36+
37+
- 원래 object.assign으로 얕은 복사를 썼으나, 예상한 방식대로 동작하지 않아 깊은 복사를 지원하는 deepCopy 유틸을 만들었습니다
38+
- 메서드는 검색을 통해 참고했으나, 참조 레퍼런스의 순수한 값만 복사하는 deep copy의 작동 방식은 이해했습니다
39+
40+
#
41+
42+
#### 4. comment : 시작하는 것은 굳이 class로 만들지 않아도 될거 같아요. 사용일 될 일이 정말 없을 거 같은 부분이기도 하니까요.
43+
44+
```javascript
45+
const RunTodoApp = class {
46+
constructor() {
47+
this.cmdArr = ['show','delete','update','add','undo','redo'];
48+
this.commandParser = new CommandParser();
49+
```
50+
51+
- 프로그램 실행을 담당하는 app.js의 class를 제거한 후, 리팩토링했습니다.
52+
53+
#
54+
55+
#### 5. comment : promise패턴을 사용했는데요. then메서드를 사용했을때의 장점은 무엇이라고 생각되세요?
56+
57+
```javascript
58+
this.utils.delay(0)
59+
.then(() => {if (cmdList[0] === 'update') return this.utils.delay(3500);})
60+
```
61+
62+
- then메서드를 사용했을 경우, 새로운 프로미스 객체가 반환되어 여러 개의 Promise를 체이닝할 수 있습니다.
63+
- 따라서, 여러 개의 비동기 작업을 수행할 경우, 보다 쉽게 비동기를 제어할 수 있다는 장점이 가장 큰 장점 같습니다.
64+
- error 처리 또한 catch로 손쉽게 할 수 있다는 점도 장점입니다.
65+
66+
#
67+
68+
#### 6. comment : 이부분은 객체리터럴 vs. 클래스! 중 어떤 것이 더 어울릴까요?
69+
```javascript
70+
const CustomException = class {
71+
```
72+
- 에러 처리는 변하는 값이 아닌 특수한 상황에서만 사용되는 고정된 값입니다. 따라서 동적인 인스턴스를 지원하는 class를 사요할 필요 없이
73+
속도가 빠르고 메모리 자원을 낭비하지 않는 리터럴이 적합하다 생각합니다.

class/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## STEP5-3 : TUNA & YM 리뷰 내용 반영
2+
3+
#
4+
#### 1. comment : 전체코드의 들여쓰기가 너무 깊은데요? 좋은 indent 가 무엇인지 한번찾아볼래요?
5+
6+
- 전체 코드 indent 수정 : tab 인덴트를 space * 4 로 수정
7+
- 원인 : pair를 위해 구름 ide에서 작업 중, local으로 옮기면서 indent 오반영
8+
9+
원래 ide의 설정은 tab이 space * 4 의 indent로 설정되어 있습니다.
10+
앞으로 들여쓰기가 올바르게 되어있는지, 불편하지 않은지 신경쓰도록 하겠습니다
11+
12+
#
13+
14+
#### 2. comment : 주석이 필요한.. arguments.length 로 구별하는 방식을 어떻게 개선할 수 있을까요?
15+
16+
- 리뷰 이전
17+
```javascript
18+
if (argument.length === 3) // updaste
19+
...
20+
} else if (arguments.length === 2) { // add, delete
21+
```
22+
23+
- 리뷰 이후 : 의미가 불분명해 주석이 필요했던 if statement 수정
24+
25+
```javascript
26+
if (command === 'update') {
27+
...
28+
} else if (command === 'add' || command === 'delete') {
29+
...
30+
}
31+
```
32+
33+
#
34+
35+
#### 3. utils 클래스의 deepCopy 메서드의 이해
36+
37+
- 원래 object.assign으로 얕은 복사를 썼으나, 예상한 방식대로 동작하지 않아 깊은 복사를 지원하는 deepCopy 유틸을 만들었습니다
38+
- 메서드는 검색을 통해 참고했으나, 참조 레퍼런스의 순수한 값만 복사하는 deep copy의 작동 방식은 이해했습니다
39+
40+
#
41+
42+
#### 4. comment : 시작하는 것은 굳이 class로 만들지 않아도 될거 같아요. 사용일 될 일이 정말 없을 거 같은 부분이기도 하니까요.
43+
44+
```javascript
45+
const RunTodoApp = class {
46+
constructor() {
47+
this.cmdArr = ['show','delete','update','add','undo','redo'];
48+
this.commandParser = new CommandParser();
49+
```
50+
51+
- 프로그램 실행을 담당하는 app.js의 class를 제거한 후, 리팩토링했습니다.
52+
53+
#
54+
55+
#### 5. comment : promise패턴을 사용했는데요. then메서드를 사용했을때의 장점은 무엇이라고 생각되세요?
56+
57+
```javascript
58+
this.utils.delay(0)
59+
.then(() => {if (cmdList[0] === 'update') return this.utils.delay(3500);})
60+
```
61+
62+
- then메서드를 사용했을 경우, 새로운 프로미스 객체가 반환되어 여러 개의 Promise를 체이닝할 수 있습니다.
63+
- 따라서, 여러 개의 비동기 작업을 수행할 경우, 보다 쉽게 비동기를 제어할 수 있다는 장점이 가장 큰 장점 같습니다.
64+
- error 처리 또한 catch로 손쉽게 할 수 있다는 점도 장점입니다.
65+
66+
#
67+
68+
#### 6. comment : 이부분은 객체리터럴 vs. 클래스! 중 어떤 것이 더 어울릴까요?
69+
```javascript
70+
const CustomException = class {
71+
```
72+
- 에러 처리는 변하는 값이 아닌 특수한 상황에서만 사용되는 고정된 값입니다. 따라서 동적인 인스턴스를 지원하는 class를 사요할 필요 없이
73+
속도가 빠르고 메모리 자원을 낭비하지 않는 리터럴이 적합하다 생각합니다.

class/app.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const readline = require('readline').createInterface( {
2+
input:process.stdin,
3+
output:process.stdout,
4+
});
5+
6+
const CommandParser = require('./commandParser.js');
7+
const Utils = require('./utils.js');
8+
const Instruction = require('./instruction.js');
9+
const CustomException = require('./customException.js');
10+
11+
const commandArr = ['show','delete','update','add','undo','redo'];
12+
const commandParser = new CommandParser();
13+
const instruction = new Instruction();
14+
15+
const run = (() => {
16+
readline.setPrompt('명령하세요: ');
17+
readline.prompt();
18+
readline.on('line', (userInput) => {
19+
20+
try {
21+
CustomException.missingSeperatorException(userInput);
22+
const commandList = commandParser.getCommandList(userInput);
23+
24+
CustomException.CommandMissingException(commandList[0], commandArr);
25+
commandParser.executeCommand(commandList);
26+
27+
Utils.delay(0)
28+
.then(() => {if (commandList[0] === 'update') return Utils.delay(3500);})
29+
.then(() => {return Utils.delay(1000);})
30+
.then(() => {if (commandList[0] !== 'show') instruction.show('all');})
31+
.catch(function(e) {console.log(e);})
32+
.then(() => {readline.prompt();});
33+
34+
} catch(e) {
35+
console.error(e.message);
36+
readline.prompt();
37+
}
38+
39+
}).on('close', () => {
40+
console.log("프로그램을 종료합니다.");
41+
process.exit();
42+
});
43+
})();

class/commandParser.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const Instruction = require('./instruction.js');
2+
const CustomException = require('./customException.js');
3+
4+
const CommandParser = class {
5+
6+
constructor() {
7+
this.instruction = new Instruction();
8+
}
9+
10+
getCommandList(input) {
11+
const regexp = /[^\$]+|undo|redo/g;
12+
return input.match(regexp);
13+
}
14+
15+
executeCommand(command) {
16+
try {
17+
18+
let [primaryCommand, firstSubCommand, secondSubCommand] = [command[0], command[1], command[2]];
19+
20+
if (command.length === 1) {
21+
this.instruction[primaryCommand]();
22+
} else if (command.length === 2) {
23+
this.instruction[primaryCommand](firstSubCommand);
24+
} else if (command.length === 3) {
25+
this.instruction[primaryCommand](firstSubCommand, secondSubCommand);
26+
} else {
27+
CustomException.CommandMissingException();
28+
}
29+
30+
} catch (e) {
31+
console.error(e.message);
32+
return;
33+
}
34+
}
35+
36+
isValidCommand(command, arr) {
37+
if (arr.includes(command)) return true;
38+
return false;
39+
}
40+
};
41+
42+
module.exports = CommandParser;

class/customException.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const CustomException = {
2+
missingSeperatorException : function(input) {
3+
if (!this.isValidSeperator(input)) throw new Error("구분자 $가 존재하지 않습니다");
4+
},
5+
6+
notExistIdException : function() {
7+
throw new Error(`찾으시는 id가 존재하지 않습니다`);
8+
},
9+
10+
sameStatusException : function() {
11+
throw new Error(`같은 상태로 업데이트 할 수 없습니다`);
12+
},
13+
14+
CommandMissingException : function(command, arr) {
15+
if (!this.isValidCommand(command, arr))
16+
throw new Error(`올바른 명령어가 아닙니다`);
17+
},
18+
19+
isValidSeperator : function(input) {
20+
let result = true;
21+
const regexp = /\$|undo|redo/g;
22+
if (input.match(regexp) == null) result = false;
23+
24+
return result;
25+
},
26+
27+
isValidCommand : function(command, arr) {
28+
if (arr.includes(command)) return true;
29+
return false;
30+
}
31+
};
32+
33+
module.exports = CustomException;

0 commit comments

Comments
 (0)