Skip to content

[이어진] 중급 TodoList 구현 + 로컬스토리지 추가 완료#2

Open
oding01 wants to merge 5 commits intoasac-assignments:mainfrom
oding01:oding01
Open

[이어진] 중급 TodoList 구현 + 로컬스토리지 추가 완료#2
oding01 wants to merge 5 commits intoasac-assignments:mainfrom
oding01:oding01

Conversation

@oding01
Copy link
Copy Markdown

@oding01 oding01 commented Dec 10, 2024

조회 기능, 추가 기능 구현

@oding01 oding01 changed the title [TODO 리스트 기능 확장하기 (초)] 이어진 과제 제출합니다. [이어진] 중급까지 구현 완료했습니다. Dec 10, 2024
Comment thread func_detail.js Outdated
const editBtn = item.querySelector('.edit-btn');
const saveBtn = item.querySelector('.save-btn');
saveBtn.style.display = 'inline';
editBtn.style.display = 'none';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 교체
}

좀 변태같긴하지만 저 개인적으론 코드의 형상을 맞추는걸 선호하는 편입니다.
다른 사람이 코드보았을때 명확히 이해가능하거든요. 물론 개발 시간이 넉넉하다는 전제하에

Comment thread func_detail.js Outdated
const button = document.createElement(tag);
button.textContent = buttonText;
button.classList.add(className);
button.addEventListener('click', (e) => { handleButtonEvent(e) } );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 또한 파라미터로 받으면됩니다 :) 아래 handleButtonEvent 에서 분기타는게 이뻐보일수도 있긴한데
차라리 이런 형태로 갈거라면 createButton 의 파라미터를 객체로 변경한 뒤
각 버튼타입의 객체를 Enum 처럼 const 로 정의해놓아
createButton 에 특정 타입의 객체 파라미터를 주면 그 객체 내 요소들 가져다가 타입 버튼을 만드는게 좋을듯해요.

@oding01 oding01 changed the title [이어진] 중급까지 구현 완료했습니다. [이어진] 중급 TodoList 구현 + 로컬스토리지 추가 완료 Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants