[1팀 한아름] Chapter 1-2. 프레임워크 없이 SPA 만들기 (2)#49
Open
areumH wants to merge 17 commits into
Open
Conversation
DEV4N4
reviewed
Jul 19, 2025
| // VirtualDOM을 RealDOM으로 변환 | ||
| export function createElement(vNode) { | ||
| // null, undefined, boolean 값은 빈 텍스트 노드로 변환 | ||
| if (typeof vNode === "boolean" || vNode === null || vNode === undefined) { |
There was a problem hiding this comment.
아름님! null과 undefined를 느슨한 비교를 통해 동시에 비교하는 문법도 나쁘지 않은 것 같아서 제안 드리려구 가져왔어요!!
toss/frontend-fundamentals#189
토스에서는 null과 undefined를 같이 걸러야 하는 케이스에서 대부분 느슨한 비교를 사용한다고 해요! 참고하시라구 남겨드립니다!
Author
There was a problem hiding this comment.
느슨한 비교라는 개념이 있군요!!! 링크까지 감사합니다😶😶
DEV4N4
reviewed
Jul 19, 2025
| return { | ||
| type, | ||
| props, | ||
| children: children.flat(Infinity).filter((child) => child !== false && child !== null && child !== undefined), |
There was a problem hiding this comment.
Suggested change
| children: children.flat(Infinity).filter((child) => child !== false && child !== null && child !== undefined), | |
| children.flat(Infinity).filter((x) => x || x === 0), |
요렇게 바꾸는 방식은 어떠실까여!
|
disabled, checked, required, readonly 같은 boolean 속성들 처리에 대한 트러블 슈팅기 좋네요 :) 자료구조를 적절히 사용했는지는 한번 각 객체에 대한 속성을 정리해보면 좋을것 같네요 WIL기대 하겠습니당 👍 이번 과제 무난히 수행하신것 같아 간단히 남깁니당 아름님 2주차도 수고많으셨어용! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
과제 체크포인트
배포 링크
https://areumh.github.io/front_6th_chapter1-2/
기본과제
가상돔을 기반으로 렌더링하기
이벤트 위임
심화 과제
Diff 알고리즘 구현
과제 셀프회고
기술적 성장
가상 돔에 대한 사전적 정의와 사용 이유에 대해서만 얕게 알고 있었는데, 이번 과제를 통해 가상 DOM과 실제 DOM의 동작 차이, 이벤트 위임과 버블링의 구체적인 동작 방식 등에 대해 더 깊이 알게 된 것 같다.
코드 품질
현재는 과제로 출제된 각 함수 파일 그대로 구현했는데, 추후에 리팩토링을 한다면 createElement, normalizeVNode 함수에서 조건문에 사용되는 vNode의 타입을 확인하는 함수를 따로 작성하고 싶다. 그리고 updateElement 함수 내에서 속성 업데이트에 사용되는 updateAttribute 함수가 가독성 면에서 조잡해보이는 느낌이 있어서 만약 리팩토링을 한다면 유틸 함수로 역할을 분리하거나 createElement의 updateAttribute에도 재사용할 수 있는 함수로 분리하여 진행해보고 싶다.
학습 효과 분석
updateElement에서 boolean 타입의 속성 값을 업데이트할 때 createElement에서와 같은 동작인
setAttribute(attr, "")으로 작성하여 헤맨 기억이 있다.실제 DOM은 직접 속성을 업데이트해줘야 하기 때문에
target[attr] = value;처럼 해당 속성이 존재할 경우엔 값을 직접 업데이트해주도록 하여 해결했다.처음 setupEventListener 함수를 작성했을 때, 이벤트 실행 시 해당 요소에 등록된 이벤트만을 검사하여 실행하도록 구현했는데 이 때문에 제일 기본적인 페이지 라우트 테스트를 통과하지 못해 많은 시간을 허비했다.
위의 코드처럼 현재 요소의 부모 요소를 하나씩 검사하면서 이벤트 함수가 있으면 해당 이벤트를 실행하도록 코드를 수정하여 해결했다.
과제 피드백
이번 과제를 통해 가상 돔을 다뤄보면서, 평소라면 깊게 고민하지 않았을 부분까지 깊이 있게 이해할 수 있었습니다. 만약 이번 과제처럼 구체적으로 다뤄보는 기회가 없었다면, 가상 돔이 어떻게 동작하는지, 왜 필요한지에 대해 학습할 일은 없었을 것 같아서 의미있었다고 생각한다!!
리뷰 받고 싶은 내용
setupEventListener 함수에서 이벤트 핸들러 저장, root에 연결된 이벤트 관리에 Map이 적절히 사용된건지 의견을 여쭤보고 싶습니다. (이벤트를 연결하는 데에 더 좋은 방안이 있는지.) 그리고 어떠한 요소에 대해 발생해야 하는 이벤트가 부모 요소에 연결된 이벤트일 경우
event.currentTarget을 사용하여 부모 요소를 차례로 확인하여 연결하도록 구현하였는데, 이 또한 적절한 방식인지 궁금합니다.