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 돔 조작과 이벤트 핸들링으로 메뉴 관리하기 #270

Open
wants to merge 10 commits into
base: shinseongsu
Choose a base branch
from

Conversation

shinseongsu
Copy link

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

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

🔥 만들면서 생각한것

  1. menu 라는 배열을 만들어 데이터 관리를 하고 수정이나 추가가 일어날 시, 화면을 다시 그리도록 하였습니다.
  2. 중복을 제거하고자 최대한 모듈 형식으로 만들려고 노력했습니다.

@@ -14,6 +14,9 @@
</a>
</p>

# 팀원 이름 넣기
## 성수님, 세빈님, 도현님, 재원님, 경아, 지혜님 환영합니다~
Copy link

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.

헉 제가 오타를 냈네요 ㅠㅠ 수정 빠르게 하도록 하겠습니다
춤을 추는 ㅎㅎ 까먹지않겠네요 ㅎㅎ

import { DELETE_MESSAGE, EDIT_MESSAGE } from '../common/constants.js';

function Menu() {
this.$inputText = document.getElementById("espresso-menu-name");
Copy link

Choose a reason for hiding this comment

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

강의에 나온 거지만, 저는 const $ = (selector) => document.querySelector(selector) 처럼 DOM을 선택할 수 있는 유틸 함수를 만들어서 했는데, 코드 반복이 줄어서 편했어요!

Copy link
Author

Choose a reason for hiding this comment

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

아 그렇네요 ㅎㅎ 감사합니다 좋은 방법이네요


this.editEvent = (event) => {
const newValue = prompt(EDIT_MESSAGE);
const menuId = event.target.closest("li").dataset.menuId;
Copy link

Choose a reason for hiding this comment

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

오.. 이벤트 리스너 자체는 각 버튼에 달려있는데 이벤트 발생하면 제일 가까운 상위 li 태그를 찾는거죠? 이런 방법도 있었네요!! 😲 closest 문법 알아갑니다!

제가 문벅스 가이드북의 event에 대한 글을 읽었는데, 이벤트 리스너가 달린 요소가 많을 수록 페이지 실행 속도가 늦어진다는 구절이 있었어요! 그래서 부모 요소에 이벤트 리스너를 달아서 자식 요소에 이벤트가 발생했을 때 해당 이벤트를 캡쳐해서 사용하도록 이벤트 위임을 사용해봐도 좋을 것 같아요! 저도 잘은 모르지만ㅎㅎ url 첨부합니다! EVENT

Copy link
Author

Choose a reason for hiding this comment

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

링크까지 감사합니다 😄
캡처링, 버블링 이런 요소들이 많이 있었네요

Copy link

@maddrake220 maddrake220 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

@@ -0,0 +1,16 @@
function MenuCount() {
this.$menuCount = document.getElementsByClassName("menu-count")[0];

Choose a reason for hiding this comment

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

querySelector 보다 getElementByClassName을 쓰신 이유가 성능 적인 이슈 때문에 쓰신 건지 어떤 이유에서 쓰신 건지 궁금합니다!

Copy link
Author

Choose a reason for hiding this comment

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

querySelector 보다 getElementById 나 getElementByClassName 같이 명확하게 알수 있을 것같아서 사용했었습니다
https://bobbohee.github.io/2021-02-12/getelementbyid-versus-queryselector
찾아보니깐 속도도 별로 차이도 없고 짧게 쓸수 있고 재사용성도 높은 querySelecto를 좋아하나보네요~
생각할 수 있는 코멘트 남겨주셔서 감사합니다

document.addEventListener('DOMContentLoaded', () => {
const app = new App();
app.render();
});

Choose a reason for hiding this comment

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

파일마다 end of line 추가 하시면 좋을 것 같습니다!
github에서 No newline at end of file 떠서 찾아보니 이런 글이 있어서 남겨볼게요!

https://coderifleman.tumblr.com/post/115464362564/%ED%8C%8C%EC%9D%BC-%EB%81%9D%EC%97%90-%EA%B0%9C%ED%96%89%EC%9D%84-%EC%B6%94%EA%B0%80%ED%95%B4%EC%95%BC-%ED%95%98%EB%8A%94-%EC%9D%B4%EC%9C%A0

Copy link
Author

Choose a reason for hiding this comment

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

아 그렇군요 감사합니다
리액트나 뷰를 할때는 prettier 때문에 알아서 마지막 개행을 생각 안했었네요

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.

3 participants