-
Notifications
You must be signed in to change notification settings - Fork 375
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 돔 조작과 이벤트 핸들링으로 메뉴 관리하기 #268
base: areumsheep
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
안녕하세요 조이!
리뷰 남겨주셔서 정말 감사해욧! ㅎㅎ
저도 다른 팀이지만 리뷰 조금 남겨 보았어요!
남은 기간 같이 잘해봐요~! 👍
if (deleteFlag) { | ||
const deleteMenu = currentTarget.closest('.menu-list-item'); | ||
deleteMenu.remove(); | ||
} | ||
updateEspressoMenuCount(-1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (deleteFlag) { | |
const deleteMenu = currentTarget.closest('.menu-list-item'); | |
deleteMenu.remove(); | |
} | |
updateEspressoMenuCount(-1); | |
if (!deleteFlag) { | |
return; | |
} | |
const deleteMenu = currentTarget.closest('.menu-list-item'); | |
deleteMenu.remove(); | |
updateEspressoMenuCount(-1); |
지금은 취소를 눌러도 updateEspressoMenuCount
가 호출되네요 early return
이 이런 오류를 예방하기 좋은 것 같아요! 😀
@@ -0,0 +1,5 @@ | |||
export function $(selector) { | |||
const element = document.querySelector(selector); | |||
if (element === null) throw new Error('element is null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selector 이름을 만약에 잘못 입력 했을 때 예외처리를 안 해주게 되면 다음 스크립트가 동작을 안하게 되겠네요.!
엄격하게 체크하려고 의도 하신 건지 궁금해요~!😮
|
||
espressoMenuList.addEventListener('click', (event) => { | ||
const currentTarget = event.target; | ||
switch (currentTarget?.dataset.action) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
옵셔널체이닝
좋네요! 👍 data로 이벤트를 분기 하는 것 도 좋은 것 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dataset 을 사용해서 switch 쓰도록 한 방식 좋네요! 저도 사용해봐야겠네용 ㅎㅎ
event.preventDefault(); | ||
const menuName = espressoMenuInput.value; | ||
|
||
if (menuName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
early return
해주면 뒤 코드의 흐름을 보기 더 쉬울 것 같아요~!
let orderedMenuCount = 0; | ||
const espressoMenuCount = $('.menu-count'); | ||
const espressoMenuForm = $('#espresso-menu-form'); | ||
const espressoMenuInput = $('#espresso-menu-name'); | ||
const espressoMenuList = $('#espresso-menu-list'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용되는 변수들을 모아두니 보기 편하네요! 😀
const currentTarget = event.target; | ||
switch (currentTarget?.dataset.action) { | ||
case 'edit': | ||
const newMenuName = prompt('메뉴명을 수정하세요.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기 메뉴 이름이 비어 있을 때도 체크해주면 좋을 것 같아요~!
</button> | ||
<button | ||
type="button" | ||
data-action="delete" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 name attribute 를 추가하여 이벤트를 분기했는데 data-action을 사용하셨네요 !👍
const espressoMenuInput = $('#espresso-menu-name'); | ||
const espressoMenuList = $('#espresso-menu-list'); | ||
|
||
const updateEspressoMenuCount = (number) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, -1 를 인자로 넘겨서 처리 하셨군요!
menu list의 length를 활용하는 방법도 고려해보면 좋을것 같아요 !
🎯 step1 요구사항 - 돔 조작과 이벤트 핸들링으로 메뉴 관리하기
prompt
인터페이스를 활용한다.confirm
인터페이스를 활용한다.<ul id="espresso-menu-list" class="mt-3 pl-0"></ul>
안에 삽입해야 한다.✨ 상세 설명
dom.js
index.js
onSubmit
이벤트를 추가하여 input에 메뉴 이름이 입력되어 있을 시 메뉴 리스트에 메뉴를 추가한다.reset()
을 활용하여 input을 빈 값으로 초기화한다.updateEspressoMenuCount()
함수를 호출한다.#espresso-menu-list
)에 이벤트를 추가하여 이벤트 위임을 통해 자식에게 전달되도록 한다.data-action
으로 어떤 버튼이 클릭되었는지 확인한다.updateEspressoMenuCount()
함수를 호출한다.🤔 더 고민해보고 싶은 것
index.js
에 모든 걸 다 맡기는 식으로 개발을 하였습니다...🥲 이후에 메뉴별로 상태를 관리해야 할 경우를 대비하여 남은 시간동안 더 고민해볼게요!