11//createElement함수는 가상돔을 돔으로 변환해주는 것
2- import { addEvent } from "./eventManager " ;
2+ import { updateAttributes } from "./updateElement " ;
33
44export function createElement ( vNode ) {
55 if ( vNode === null || vNode === undefined || typeof vNode === "boolean" ) {
@@ -18,36 +18,13 @@ export function createElement(vNode) {
1818 return fragment ;
1919 }
2020
21- // if (typeof vNode.type === "function") {
22- // const { props = {}, children = [] } = vNode;
23- // const nextVNode = vNode.type({ ...props, children });
24- // return createElement(nextVNode);
25- // }
2621 if ( typeof vNode . type === "function" || ( typeof vNode . type === "object" && typeof vNode . type . type === "function" ) ) {
2722 throw new Error ( "컴포넌트는 createElement로 직접 처리할 수 없습니다. 먼저 normalizeVNode로 정규화하세요." ) ;
2823 }
2924
3025 const $el = document . createElement ( vNode . type ) ;
3126
32- Object . entries ( vNode . props || { } ) . forEach ( ( [ key , value ] ) => {
33- if ( key . startsWith ( "on" ) && typeof value === "function" ) {
34- const eventName = key . slice ( 2 ) . toLowerCase ( ) ;
35- addEvent ( $el , eventName , value ) ;
36- } else if ( key === "className" ) {
37- $el . setAttribute ( "class" , value ) ;
38- } else if ( key === "style" && typeof value === "object" ) {
39- Object . entries ( value ) . forEach ( ( [ styleName , styleValue ] ) => {
40- $el . style [ styleName ] = styleValue ;
41- } ) ;
42- } else if ( key . startsWith ( "data-" ) ) {
43- $el . setAttribute ( key , value ) ;
44- } else if ( typeof value === "boolean" ) {
45- if ( value ) $el . setAttribute ( key , "" ) ;
46- // false면 아무것도 안 함
47- } else {
48- $el . setAttribute ( key , value ) ;
49- }
50- } ) ;
27+ updateAttributes ( $el , vNode . props || { } , { } ) ;
5128
5229 const children = Array . isArray ( vNode . children ) ? vNode . children : [ ] ;
5330 children . forEach ( ( child ) => {
@@ -56,5 +33,3 @@ export function createElement(vNode) {
5633
5734 return $el ;
5835}
59-
60- //function updateAttributes($el, props) {}
0 commit comments