[1팀 김민석] Chapter2-2. 나만의 React 만들기 #58
Open
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://kju1018.github.io/front_7th_chapter2-2/
기본과제
가상돔을 기반으로 렌더링하기
이벤트 위임
심화 과제
Diff 알고리즘 구현
과제 셀프회고
아하! 모먼트 (A-ha! Moment)
해당 코드가 역할을 한다는것을 알 수 있게되었습니다.
또한, vite.config.js 파일에 아래 부분도 해당 역할을 한다는것을 알 수 있게되었습니다.
이 중복 등록의 원인은 renderElement가 매 렌더마다 registerEventHandlers를 호출해서, 이미 존재하는 DOM 요소에도 이벤트 핸들러를 계속 다시 붙이고 있었던 부분이었습니다.
그래서 renderElement에서의 registerEventHandlers 호출을 제거하고, updateElement 내부에서 새 DOM 요소를 새로 만들거나 교체하는 경우에만 registerEventHandlers를 호출하도록 변경하여, 이벤트가 한 번만 등록되도록 수정했습니다.
기술적 성장
코드 품질
이번 과제는 AI에게 구현 요청 후 코드를 이해하는 방식으로 과제를 진행해서 코드품질은 좀 더 봐야알거같습니다.
학습 효과 분석
JSX가 결국 createVNode(type, props, ...children) 같은 함수 호출로 변환된다는 것을 알 수 있게되었습니다. 또한 { type, props, children } 같은 가상 DOM 노드의 최소 단위 모델이 어떤식으로 되어있는지, children을 평탄화하고 null/undefined/boolean을 제거하면서 렌더 가능한 데이터 구조로 정리하는 패턴을 알 수 있었습니다.
newNode / oldNode를 비교해서 타입이 같으면 속성만 업데이트, 타입이 다르면 교체, 자식 배열 길이 비교해서 추가/삭제, 하는 간단하지만 실제 동작하는 diff 알고리즘 동작과정을 보면서 Diff 알고리즘에대해 학습할 수 있었습니다.
과제 피드백
리뷰 받고 싶은 내용
AI가 대부분 작성해주고 그 부분을 이해하고 외우는 방식으로 학습을 진행해서 리뷰 받고 싶은 내용은 없습니다! 좀 더 공부해보겠습니다