Skip to content

Conversation

@skojphy
Copy link

@skojphy skojphy commented Jul 24, 2022

버그가 개많지만 시간이 없어서 일단 올립니다😭

@skojphy skojphy changed the title [혜연] JS 자판기 미션 제출 [서혜연] JS 자판기 미션 제출 Jul 24, 2022
Copy link

@piggmme piggmme left a comment

Choose a reason for hiding this comment

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

수고 많으셨어요 혜연님~!

document.querySelector('#app section').innerHTML = TEMPLATES.PRODUCT_ADD;

products.forEach(product => {
renderProduct(product);
Copy link

Choose a reason for hiding this comment

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

renderProduct 함수 내부를 보니까 product를 real dom에 append 해주고있더라구요.
그래서 forEach로 순회하면 매번 append 하면서 reflow가 발생하네요
한번에 모아서 붙이는 방법을 사용하면 성능 면에서 더 좋았을 것 같아요!

$productAddMenuButton,
$vendingMachineManageMenuButton,
$productPurchaseMenuButton
);
Copy link

Choose a reason for hiding this comment

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

요 버튼 만드는 부분 위에서 배열 순회하면서 했던 방법처럼 하면 중복을 더 줄일 수 있을거같아용!

  const [ $productAddMenuButton, $vendingMachineManageMenuButton, $productPurchaseMenuButton  ] = 
    navList.map(({ tagName,  id, innerText })=>
      createEl({  tagName,  id, innerText })
  );

tagName: 'button',
className: 'purchase-button',
innerText: '구매하기',
});
Copy link

Choose a reason for hiding this comment

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

여기도 중복이 많은데 위에 커멘트 한것처럼 줄일 수 있지 않을까용?

if (innerText) $el.innerText = innerText;

return $el;
};
Copy link

Choose a reason for hiding this comment

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

props로 children 받아서 자식 append도 할 수 있게 기능 추가하면 유용할것같아요!

export const createEl = ({ tagName, id, className, innerText, children }) => {
  const $el = document.createElement(tagName);

  if (id) $el.id = id;
  if (className) $el.classList.add(className);
  if (innerText) $el.innerText = innerText;
  if(children) $el.append(children);

  return $el;
};

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

@jkpark104 jkpark104 left a comment

Choose a reason for hiding this comment

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

고생했어요~~ 👍

alert(ERROR_MSG.PRODUCT_MIN_PRICE);
} else if (price % 10) {
alert(ERROR_MSG.PRODUCT_MIN_PRICE_UNIT);
} else if (quantity < 1) {

Choose a reason for hiding this comment

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

else if로 걸면 100원 이상 양이 1 미만인 경우는 못거르지 않나요?

만약 그렇다면 if로 해야할 것 같아요
if (a조건 || b조건) 이런식으러?

const newProduct = {
name: name,
price: price,
quantity: quantity,

Choose a reason for hiding this comment

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

축약표현을 쓰면 훨씬 가독성이 좋을 것 같아요

tagName: 'tr',
className: 'product-manage-item',
});
const [$newProduct_name, $newProduct_price, $newProduct_quantity] = [

Choose a reason for hiding this comment

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

음 돔이라 그런걸 수도 있지만 변수명은 카멜케이스로 하는게 객체에 접근할 때 대괄호 접근자를 안 써도 돼서 장기적인 가독성 측면에서 더 좋을 것 같네요

renderProductsList();
renderChange();

document.querySelector('form').addEventListener('submit', handleInsertCharge);

Choose a reason for hiding this comment

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

저도 못한 부분이지만 돔을 선언하는 모듈이 있고 그 모듈 돔 변수들을 사용하거나 정민님처럼 $ 유틸함수를 사용하면 가독성이 더 좋아질 것 같네요

const currentCharges = getValueFromLocalStorage('charges', []);
currentCharges.forEach(charge => {
const currentChargeAmount = chargeAmount;
const coinCount = Math.min(parseInt(currentChargeAmount / charge.coinValue), charge.quantity);

Choose a reason for hiding this comment

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

중복돼 사용되는 변수는 디스트럭처링 할당하면 더 좋을 갓 같아요

const currentCharges = getValueFromLocalStorage('charges', []);
currentCharges.forEach(charge => {
const currentChargeAmount = chargeAmount;
const coinCount = Math.min(parseInt(currentChargeAmount / charge.coinValue), charge.quantity);

Choose a reason for hiding this comment

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

파스인트는 원래 목적이 스트링 to 숫자인걸로 알고있는데 Math.floor를 쓰면 목적이 더 분명할 것 같네요

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.

4 participants