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

[1주차] 한서정 미션 제출합니다. #9

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

Conversation

xseojungx
Copy link

@xseojungx xseojungx commented Mar 15, 2025

배포 링크

1주차 과제

느낀점

  1. 디자이너의 소중함🥹 DOM 조작보다 css 만들고 디자인한 시간이 더 걸린 것 깉아요...
  2. 리액트 같은 프레임워크의 소중함🥹 랜더링 기능을 수동으로 처리하니 랜더링코드, 기능 담당 함수들이 섞이며 가독성이 너무 떨어진다.
  3. 미션을 잘 읽자... 기능별로 커밋 메세지를 작성해야 하는걸 못 봐서 한번에 커밋해버렸습니다... 다음부터 꼼꼼하게 체크하겠습니다.

Key Questions

1. DOM은 무엇인가요?

  • DOM(Document Object Model)은 웹 브라우저가 HTML 문서를 이해하고 조작할 수 있도록 트리 구조의 객체로 변환한 것이다.
  • 쉽게 말하면, HTML 문서를 자바스크립트에서 다룰 수 있도록 구조화한 것이다.
  • DOM을 통해 HTML 요소를 가져오고, 수정하고, 새로운 요소를 추가하는 것이 가능하다.

내 코드에서 DOM을 활용한 예시

  • document.getElementById("add-tag")를 사용해서 <select id="add-tag"></select> 요소를 가져옴.
const dropDown = document.getElementById("add-tag");
  • 이런 방식으로 DOM을 활용하면 HTML 요소를 자바스크립트에서 동적으로 조작할 수 있다.

2. 이벤트 흐름 제어(버블링 & 캡처링)이 무엇인가요?

  • 이벤트 흐름(Event Flow)*이란 이벤트가 발생할 때, 브라우저가 이벤트를 처리하는 방식을 의미한다.
  • 이벤트 흐름에는 버블링(Bubbling)과 캡처링(Capturing) 두 가지 방식이 있ㅇ ㅁ

버블링(Bubbling)

  • 이벤트가 가장 안쪽 요소에서 시작하여 바깥쪽 요소로 전파되는 방식이다.
  • 예를 들어, <button>을 클릭하면 button → div → body 순서로 이벤트가 전달된다.
document.getElementById("add-todo").addEventListener("click", addTodo);
  • 위 코드에서 #add-todo 버튼을 클릭하면 addTodo() 함수가 실행된다.
  • 만약 부모 요소인 #todo-list-container에도 click 이벤트가 등록되어 있다면, 버튼을 클릭한 후에도 이벤트가 부모 요소까지 전달될 수 있다.

캡처링(Capturing)

  • 이벤트가 가장 바깥쪽 요소에서 시작하여 안쪽 요소로 전달되는 방식이다.
  • addEventListeneruseCapture 옵션을 true로 설정하면 캡처링이 활성화된다.

3. 클로저와 스코프가 무엇인가요?

스코프(Scope)

  • 변수가 접근할 수 있는 범위를 의미한다.
  • 자바스크립트에서 변수는 함수 스코프(함수 내부에서만 접근 가능) 또는 **블록 스코프(중괄호 {} 내부에서만 접근 가능)**를 가짐
function addTodo() {
    const text = document.getElementById("todo-input-text").value.trim();
    if (text === "") return alert("할 일을 입력해주세요.");
}

console.log(text); // ❌ Error: text is not defined (함수 스코프)

  • 위 코드에서 text 변수는 addTodo() 함수 내부에서 선언되었기 때문에 함수 외부에서는 접근할 수 없음
  • 함수 내부에서 선언된 변수는 외부에서 접근할 수 없음

클로저(Closure)

  • 클로저는 함수가 선언될 때의 스코프를 기억하고, 해당 스코프에 접근할 수 있는 기능을 말함
  • 쉽게 말하면, 외부 함수의 실행이 끝난 후에도 내부 함수가 외부 함수의 변수에 접근할 수 있도록 하는 것이다.
  • createTagManager() 함수가 실행될 때 tagCount 변수가 생성되지만, 내부 함수(addTag())가 계속 접근할 수 있다.
  • 즉, 클로저를 활용하면 어떤 값을 기억하고 유지하는 것이 가능하다.

정리

📌 정리

개념 설명 코드 예시
DOM HTML을 객체화한 구조로, JS에서 HTML을 조작할 수 있도록 함 document.getElementById("add-tag")
버블링 이벤트가 안쪽 → 바깥쪽으로 전파됨 button → div → body 순서로 이벤트 발생
캡처링 이벤트가 바깥쪽 → 안쪽으로 전파됨 addEventListener("click", handler, true)
스코프 변수가 접근할 수 있는 범위 함수 내부 변수는 외부에서 접근 불가
클로저 외부 함수의 변수를 내부 함수가 기억하여 계속 접근 가능

그 외

  • id vs class 차이점
    • id: 고유한 스타일, 특정 요소에서 사용한다.
      • 한 문서에서 유일해야 함
      • 한개의 요소에만 적용 가능
      • getElementById() 를 사용해서 선택
    • class: 여러 요소에 동일한 스타일 적용.
      • 여러 요소에 같은 스타일을 적용할 때 좋다.
      • 재사용이 가능
      • JavaScript에서 getElementsByClassName() 또는 querySelectorAll()로 선택 가능

Copy link

@only1Ksy only1Ksy 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,138 @@
/* 투두 모양 json 설계

Choose a reason for hiding this comment

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

데이터를 모듈화해서 사용하시는 방식이 깔끔하고 가독성이 좋아서 인상적이에요!! 코드 작성할 때 모듈화에 대해서는 생각해 보지 못했는데 저 또한 참고해서 고민해 봐야 할 것 같습니다. 😊👍

<div id="header-div"></div>
</header>
<div class="app-container">
<section class="todo-input-section">

Choose a reason for hiding this comment

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

저는 한 번도 section 태그는 활용해 본 적이 없었는데 확실하게 구분되어 가독성이 올라가니 편한 것 같아요!

Comment on lines +310 to +311
word-break: break-word; /* 긴 단어가 있으면 줄바꿈 */
overflow-wrap: break-word; /* 박스 안에서 줄바꿈 */

Choose a reason for hiding this comment

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

혹시 줄바꿈 속성을 두 개 설정하신 이유가 있을까요??

Copy link

@seoyeon5117 seoyeon5117 left a comment

Choose a reason for hiding this comment

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

처음에 배포 링크 들어가보고 너무 잘 만드셔서 놀랐어요! css 파일에까지 주석이 달려있어서 이해하기 너무 편했고 함수명도 잘 지어주셔서 가독성이 좋았습니다,,
다만 요일별 todo 개수가 필수요건에 포함되어있어서 저도 급하게 추가했었는데 요일별 todo 개수도 확인할 수 있으면 좋았을 것 같습니다!
과제 하시느라 수고하셨습니다~!

Comment on lines +215 to +219
// 삭제 버튼
const deleteSpan = document.createElement("span");
deleteSpan.textContent = "삭제";
deleteSpan.classList.add("delete-btn");
deleteSpan.addEventListener("click", deleteTodo);

Choose a reason for hiding this comment

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

버튼은 태그를 사용하여 cursor: pointer와 같은 기본 css도 챙기고 접근성도 높이면 좋을 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

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

앗 넵 감사합니다! 수정해놓았습니다:)

padding: 10px;
gap: 4px;
border-radius: 8px;
font-size: 1rem;

Choose a reason for hiding this comment

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

font-size로 px와 rem을 섞어 사용하시는 이유가 궁금합니다!


.app-container {
width: 100%;
padding: 80px 0 24px;

Choose a reason for hiding this comment

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

여기에 padding bottom이 들어가서 아래와 같이 하단에 여백이 생기는 것 같습니다!
image

script.js Outdated
Comment on lines 268 to 272
console.log(existingTag);
if (existingTag) {
// 기존 태그에 할 일이 있는 경우 → 해당 태그의 todos 배열에 추가
existingTag.todos.push(newTodo);
} else return alert("에러");

Choose a reason for hiding this comment

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

태그가 기본적으로 선택되어 있지 않아서 그냥 등록하려고 하면 에러가 발생합니다. existingTag를 '기본'으로 설정해두고 alert 메시지도 좀 더 자세히 적어두시면 좋을 것 같아요!
image

그리고 alert 창은 확인 버튼을 누르기 전까지 사용자의 동작을 막아 UX를 저해하기 때문에 별로 좋지 않다고 알고 있습니다. 대신 modal, toast 등을 사용하는 걸 추천드립니다!

불필요한 console.log는 삭제하면 더 좋을 것 같습니다!

Copy link
Author

Choose a reason for hiding this comment

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

이런 에러가 있었군요.. 감사합니다 수정했서요!

} else return alert("에러");

//세션에 저장
sessionStorage.setItem("todos", JSON.stringify(todos));

Choose a reason for hiding this comment

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

localStorage 대신 페이지 세션이 끝날 때 데이터가 제거되는 sessionStorage를 사용하신 이유가 따로 있으신가요??

Comment on lines +38 to +48
const color = [
"#E3EAF5",
"#C6D3EE",
"#BCC8E6",
"#E5DFF5",
"#D7E3F3",
"#CFE0F1",
"#D9D0F2",
"#E1E7F8",
"#D0D7F1",
"#E8E3FA",

Choose a reason for hiding this comment

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

태그별로 색상 다르게 하신거 너무 예쁜 것 같습니다💕

const tagList = document.getElementById("todo-list-container");

// 태그 컨테이너 생성 공통 함수
// 처음에 innerHtml 사용했는데 찾아보니 보안상 위험하다고 해서 다시 만듬

Choose a reason for hiding this comment

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

헉 저는 그냥 innerHtml 사용했는데 꼼꼼하시군요,,

todoText.classList.add("todo-text");

//아랫줄
const dateDiv = document.createElement("div");

Choose a reason for hiding this comment

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

<div> 말고 <date> 태그 사용하면 더 좋을 것 같습니다!

Comment on lines +45 to +47
<footer>
<p>© 한서정 세오스 1주차 과제</p>
</footer>

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.

3 participants