[이어진] 중급 TodoList 구현 + 로컬스토리지 추가 완료#2
Open
oding01 wants to merge 5 commits intoasac-assignments:mainfrom
Open
Conversation
aaronryu
reviewed
Dec 13, 2024
| const editBtn = item.querySelector('.edit-btn'); | ||
| const saveBtn = item.querySelector('.save-btn'); | ||
| saveBtn.style.display = 'inline'; | ||
| editBtn.style.display = 'none'; |
Contributor
There was a problem hiding this comment.
editTodo 와 saveTodo 의 코드 흐름의 형상(?)을 유사하게 만들 수 있을거같습니다.
Pseudo code 를 써보면 아래와 같아요. 아 그리고 saveBtn 보다 saveButton 이 좋을듯합니다. 약어 지양으로
function editTodo(event) {
const item = event.target.parentNode;
const text = item.querySelector('.todo-text');
const input = createInputFromText(text);
item.replaceChild(input, text);
toggleButton('EDIT_MODE'); // 내부에서 editButton, saveButton 교체
}
function saveTodo(event) {
const item = event.target.parentNode;
const input = item.querySelector('.todo-text');
const text = createTextFromInput(input);
item.replaceChild(text, input);
toggleButton('SAVE_MODE'); // 내부에서 editButton, saveButton 교체
}
좀 변태같긴하지만 저 개인적으론 코드의 형상을 맞추는걸 선호하는 편입니다.
다른 사람이 코드보았을때 명확히 이해가능하거든요. 물론 개발 시간이 넉넉하다는 전제하에
| const button = document.createElement(tag); | ||
| button.textContent = buttonText; | ||
| button.classList.add(className); | ||
| button.addEventListener('click', (e) => { handleButtonEvent(e) } ); |
Contributor
There was a problem hiding this comment.
이 또한 파라미터로 받으면됩니다 :) 아래 handleButtonEvent 에서 분기타는게 이뻐보일수도 있긴한데
차라리 이런 형태로 갈거라면 createButton 의 파라미터를 객체로 변경한 뒤
각 버튼타입의 객체를 Enum 처럼 const 로 정의해놓아
createButton 에 특정 타입의 객체 파라미터를 주면 그 객체 내 요소들 가져다가 타입 버튼을 만드는게 좋을듯해요.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
조회 기능, 추가 기능 구현