Skip to content

이유진 - 자판기 온보딩 프로젝트#10

Open
youjincoco wants to merge 14 commits into
mainfrom
youjin
Open

이유진 - 자판기 온보딩 프로젝트#10
youjincoco wants to merge 14 commits into
mainfrom
youjin

Conversation

@youjincoco

@youjincoco youjincoco commented Nov 23, 2024

Copy link
Copy Markdown

체크 리스트

  • HTML 구조 및 CSS 레이아웃
  • 금액 표시 화면
  • 투입 버튼 과 반환 버튼
  • 상품 구매
  • 로그 기록
  • 상품명과 금액의 변경 가능성을 고려한 유연한 데이터 관리

@youjincoco youjincoco changed the title 이유진 - 자판기 온보딩 프로젝트 WIP: 이유진 - 자판기 온보딩 프로젝트 Nov 23, 2024
@youjincoco youjincoco changed the title WIP: 이유진 - 자판기 온보딩 프로젝트 이유진 - 자판기 온보딩 프로젝트 Nov 23, 2024
@youjincoco youjincoco added the WIP 아직 작업 중입니다 label Nov 23, 2024
@youjincoco youjincoco added Needs Review 리뷰받을 준비가 되면 추가해주세요 and removed WIP 아직 작업 중입니다 labels Dec 2, 2024
Comment thread js/main.js Outdated
Comment on lines +3 to +5
window.onload = function () {
attachEventListeners();
};

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.

이 애플리케이션에서는 크게 상관없는데 JS를 추가할 때는 대체로 onload 보다는 DOMContentLoaded 이벤트가 더 선호됩니다. 혹시 모르고 계셨다면 왜 DOMContentLoaded가 더 선호되는지 찾아보시면 좋겠습니다. :)

@youjincoco youjincoco Dec 3, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

사실 DOMContentLoaded 가 더 선호되는지 모르고 있어서 찾아봤습니다!
DOMContentLoaded는 css나 이미지와 같은 외부 자원들이 로드되지 않아도 DOM이 준비되면 바로
실행되는 반면에 onload는 페이지에 포함된 모든 자원이 로드된 후에 실행되어서 페이지가 로드 완료
되는데 더 오랜 시간이 걸리기 때문에 onload를 사용해야 하는 경우가 아니면 DOMContentLoaded를 사용하는 게
더 효율적일 거 같습니다
이 애플리케이션에서는 css나 외부 자원들이 많지 않기 때문에 크게 상관없다 하신 말씀도 이해 갔습니다
감사합니다^^
수정 [b0d9bfe]

Comment thread js/main.js Outdated
attachEventListeners();
};

// 금액 포맷 함수: 항상 숫자만을 표기(양수만 입력가능),세 자리마다 쉼표를 표시합니다.

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.

이왕 설명을 쓸거라면 코드 에디터의 자동완성 혜택을 누릴 수 있도록 JSDoc 형태로 작성해보면 어떨까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

각 함수에 대한 주석을 JSDoc 형태로 작성 해봤습니다!
수정 [54e7efa]

Comment thread js/main.js Outdated

// 투입, 반환 버튼 클릭할 때
inputControls.addEventListener('click', function (event) {
if (event.target && event.target.matches('button.control-btn')) {

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.

여기서는 event.target?.matches('button.control-btn')로 줄일 수 있습니다.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

수정했습니다 감사합니다:)
수정[c805c57]

Comment thread js/main.js Outdated
// 투입, 반환 버튼 클릭할 때
inputControls.addEventListener('click', function (event) {
if (event.target && event.target.matches('button.control-btn')) {
const action = event.target.getAttribute('data-action');

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.

dataset을 사용하지 않는 이유가 있을까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

데이터 속성에 접근할 때 getAttribute 사용하는 것이 익숙해서 사용했는데
이 코드에서는 dataset을 사용하는 게 더 편리하고 직관적인 방법 같아서 수정했습니다
감사합니다:)
수정[c805c57]

Comment thread js/main.js Outdated
Comment on lines +24 to +37
const button = document.createElement('button');
button.classList.add('product-button');
button.setAttribute('data-price', product.price);

const nameDiv = document.createElement('div');
nameDiv.classList.add('product-name');
nameDiv.textContent = product.name;

const priceDiv = document.createElement('div');
priceDiv.classList.add('product-price');
priceDiv.textContent = `${formatAmount(product.price)}원`;

button.appendChild(nameDiv);
button.appendChild(priceDiv);

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.

다른 분들께도 드렸던 피드백인데 DOM을 일일이 생성하는 것보다는 template 태그를 사용해보면 어떨까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

HTML에 template태그를 추가해서 기본 구조를 미리 정의해 두고 자바스크립트에서 복제해 동적으로 추가하는 방식으로
수정 했습니다 감사합니다:)
수정[409bd97]

Comment thread js/main.js Outdated
return '';
}
// 금액을 세 자리마다 쉼표를 넣어서 포맷
let formattedAmount = Number(amount).toLocaleString('en-US');

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.

let으로 선언한 이유가 있을까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

const로 선언하는 게 더 적합한데 제가 let으로 잘못 선언한 거 같습니다ㅜㅜ
바로 수정 했습니다 감사합니다:)
수정[769e707]

Comment thread index.html
<!-- 투입 금액 표시 화면 -->
<div class="input-group">
<div class="input-display">
<input type="text" id="input-display" placeholder="0"></span>

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.

type="number"를 사용하지 않은 이유가 있을까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

금액 투입 화면에서 숫자를 입력할 때 formatAmount() 함수가 입력된 값에 쉼표를 추가하여
반환을 하기 때문에 입력 필드의 타입을 text로 설정했습니다!
만약 타입을 number를 사용하면 쉼표 문자를 입력할 수 없기 때문에 제가 원하는 금액 투입 시
포맷을 자유롭게 처리하지 못하더라구요 ㅜㅜ

Comment thread js/main.js
Comment on lines +44 to +49
const inputDisplay = document.getElementById('input-display'); // 금액 투입 박스
const inputControls = document.querySelector('.input-controls'); // 투입,반환버튼
const amountDisplay = document.getElementById('amount-display'); // 상품 금액 표시 화면
const productButtonsContainer = document.querySelector('.product-buttons'); // 상품 버튼 컨테이너
const logBox = document.querySelector('.log-box'); //로그 컨테이너
const logList = document.getElementById('log-list'); //로그 리스트 박스

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.

테스트 가능성을 고려하여 인수로 애플리케이션 루트 엘리먼트를 받고, 루트 엘리먼트 내부에서 클래스로 검색해서 대상 엘리먼트를 가져오도록 작성해 볼 수 있을까요? 그리고 클래스로 검색한 대상 엘리먼트는 "없을 수도 있다"고 가정해봅시다.

@taggon taggon added Reviewed 리뷰를 마친 상태입니다 and removed Needs Review 리뷰받을 준비가 되면 추가해주세요 labels Dec 2, 2024
@youjincoco youjincoco added WIP 아직 작업 중입니다 and removed Reviewed 리뷰를 마친 상태입니다 labels Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WIP 아직 작업 중입니다

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants