Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14기 선리] step1 돔 조작과 이벤트 핸들링으로 메뉴 관리하기 #278

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

coloringpen
Copy link

@coloringpen coloringpen commented Jul 17, 2022

이렇게 자바스크립트로 돔 조작을 본격적으로 한 건 거의 처음이나 다름없어서 떨리네요...!
뿌듯하기도 하고 즐겁기도 한데, 한편으로 코드가 너무 덕지덕지는 아닌가 싶어서 부끄럽습니다..ㅎ
앞으로도 열심히 공부해나가야겠어요..!

🎯 step1 요구사항 - 돔 조작과 이벤트 핸들링으로 메뉴 관리하기

  • 에스프레소 메뉴에 새로운 메뉴를 확인 버튼 또는 엔터키 입력으로 추가한다.
    • 메뉴가 추가되고 나면, input은 빈 값으로 초기화한다.
    • 사용자 입력값이 빈 값이라면 추가되지 않는다.
  • 메뉴의 수정 버튼을 눌러 메뉴 이름 수정할 수 있다.
    • 메뉴 수정시 브라우저에서 제공하는 prompt 인터페이스를 활용한다.
  • 메뉴 삭제 버튼을 이용하여 메뉴 삭제할 수 있다.
    • 메뉴 삭제시 브라우저에서 제공하는 confirm 인터페이스를 활용한다.
  • 총 메뉴 갯수를 count하여 상단에 보여준다.
  • 추가되는 메뉴의 아래 마크업은 <ul id="espresso-menu-list" class="mt-3 pl-0"></ul> 안에 삽입해야 한다.

Copy link

@dhrod0325 dhrod0325 left a comment

Choose a reason for hiding this comment

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

선리님 안녕하세요!
돔 조작 처음 하시는거 맞나요~?! 넘 잘 작성하신거 같은데..! ㅎㅎ
몇 가지 제 의견을 좀 남겨보았어요!
남은 기간 같이 화이팅해요~!

$munuCount.innerHTML = `총 ${menuNum}개`;
$menuNameInput.value = null;
};
const addFunc = () => {

Choose a reason for hiding this comment

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

addFunc 는 함수가 무슨 일을 하는 지 이해하기 어려우니 의도를 알 수 있도록 네이밍하면 어떨까요~?

Copy link
Author

Choose a reason for hiding this comment

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

네넵 수정해보겠습니다..!

삭제
</button>
</li>`;
if (name === '') {

Choose a reason for hiding this comment

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

name 에 대한 체크가 함수 가장 상단에 위치해서 리턴 하면 아래 코드를 읽어나가기 더 수월할 것 같아요

ealry return에 대해서도 한번 찾아보시면 좋을 것 같아요!😀

Copy link
Author

Choose a reason for hiding this comment

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

early return 이라는 건 첨 들어보네요...!!!!! 역시 공부는 멀단 걸 느낍니다ㅜ 완전 감사합니다..!


$menuList.addEventListener('click', (e) => {
if (e.target.classList.contains('menu-edit-button')) {
let edit = e.target;

Choose a reason for hiding this comment

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

위쪽은 const를 사용하고 여기부터는 let를 사용하신 이유가 궁금해요~!

Copy link
Author

@coloringpen coloringpen Jul 18, 2022

Choose a reason for hiding this comment

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

클릭할 때마다 변수 안에 들어가는 대상이 달라진다고 생각해서 let으로 처리했는데, const로 처리해도 될까요..?

Comment on lines +3 to +7
const $menuNameInput = document.querySelector('#espresso-menu-name');
const $menuForm = document.querySelector('#espresso-menu-form');
const $menuList = document.querySelector('#espresso-menu-list');
const $munuCount = document.querySelector('.menu-count');
const $menuSubmitBtn = document.querySelector('#espresso-menu-submit-button');

Choose a reason for hiding this comment

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

사용되는 돔을 상단에 모아두니 보기 다음 코드를 읽어나가기 좋은 것 같아요! 👍

Copy link
Author

Choose a reason for hiding this comment

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

리뷰 정말 감사합니다..!! 민오님 코드도 어떻게 코멘트를 하고 싶었지만 아직 제가 이해하기만도 어려운 부분들이 있는지라 코멘트는 못하고 공부만 하고 있었습니다..ㅎㅜ 계속 발전해서 스터디 끝나기 전에는 꼭...! 이것저것 코멘트 하며 리뷰도 할 수 있도록 해보겠습니다ㅎㅎ!!

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