[9팀 임규원] Chapter 1-2. 프레임워크 없이 SPA 만들기 (2)#41
Open
q1Lim wants to merge 9 commits into
Open
Conversation
fix: createElement addEvent 추가
eventHandler에서 change 이벤트 추가 updateAttribute 순서 조정 및 리팩토링
susmisc14
reviewed
Jul 18, 2025
susmisc14
left a comment
There was a problem hiding this comment.
규원님! 2주차도 고생 많으셨습니다. 포기하지 않고 끝까지 해내시려는 모습 보면서 정말 많은 자극 받았습니다. 3주차도 화이팅입니다~
There was a problem hiding this comment.
타입을 체크할 때, 'string'이나 'function' 같은 문자열을 직접 사용하는 대신 CHECK_TYPES 상수를 활용하신 점이 정말 좋은 것 같아요!
Comment on lines
+5
to
+7
| if (vNode === null || vNode === undefined || vNode === true || vNode === false) { | ||
| return ''; | ||
| } |
There was a problem hiding this comment.
vNode의 타입을 확인하는 첫 부분을 아래처럼 typeof 연산자를 사용해 불리언 체크를 합쳐주면 코드가 조금 더 간결해질 것 같아요!
if (vNode == null || typeof vNode === 'boolean') {
return '';
}
Comment on lines
+34
to
+43
| export function addEvent(element, eventType, handler) { | ||
| if (!eventRegistry.has(element)) { | ||
| eventRegistry.set(element, {}); | ||
| } | ||
| const events = eventRegistry.get(element); | ||
| if (!events[eventType]) { | ||
| events[eventType] = new Set(); | ||
| } | ||
| events[eventType].add(handler); | ||
| } |
There was a problem hiding this comment.
이벤트 핸들러를 관리하기 위해 WeakMap<Element, { [eventType]: Set }> 형태의 자료구조를 설계하신 점이 눈에 띄어요! 이렇게 중첩된 구조를 활용하면 시간 복잡도 O(1)으로 원하는 핸들러 Set에 바로 접근할 수 있어서 훨씬 성능적인 우위를 가져갈 수 있을 것 같아요.
Comment on lines
+17
to
+29
| if (Array.isArray(vNode)) { | ||
| const fragment = document.createDocumentFragment(); | ||
| vNode.forEach((child) => fragment.appendChild(createElement(child))); | ||
| return fragment; | ||
| } | ||
| const elem = document.createElement(vNode.type); | ||
|
|
||
| function updateAttributes($el, props) {} | ||
| if (vNode.children) { | ||
| vNode.children.forEach((child) => { | ||
| const childElem = createElement(child); | ||
| elem.appendChild(childElem); | ||
| }); | ||
| } |
There was a problem hiding this comment.
자식들을 forEach로 하나씩 appendChild하는 대신, map으로 모든 자식 엘리먼트를 먼저 만든 뒤 append(...elements)를 사용해 한번에 추가하면 브라우저의 리페인트 횟수를 줄여 성능상 이점을 가져갈 수 있을 것 같아요!
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://q1lim.github.io/front_6th_chapter1-2/
기본과제
가상돔을 기반으로 렌더링하기
이벤트 위임
심화 과제
Diff 알고리즘 구현
과제 셀프회고
1주차 과제를 완성하지 않았지만, 가상 DOM 구현이라는 부분은 다시 새로운 시작이라고 생각하고 과제를 진행했습니다.
기술적 성장
코드 품질
유사하게 노드의 타입을 체크하는 부분이 있었는데, 이 부분을 함수로 만들어서 공통적으로 적용할 수 있는 방향으로 만들고 싶었습니다.
normalizedVNode.js
만족스러운 구현..은 아니고 다행이었던 부분!
constants.js
학습 효과 분석
과제 피드백
리뷰 받고 싶은 내용