Last active
August 13, 2019 19:10
-
-
Save Tevinthuku/f23bfd13f2d723e266d2b91560c87c63 to your computer and use it in GitHub Desktop.
Code related to reconciliation
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
import { updateDomProperties } from "./dom-utils"; | |
import { TEXT_ELEMENT } from "./element"; | |
/** | |
* | |
* @param {object} element - vdom representation | |
* @param {HTMLElement} parentDom - element where children will be appended | |
*/ | |
export function render(element, parentDom) { | |
const { type, props } = element; | |
const isTextElement = type === TEXT_ELEMENT; | |
const dom = isTextElement | |
? document.createTextNode("") | |
: document.createElement(type); | |
updateDomProperties(dom, props); | |
const children = props.children || []; | |
children.forEach(element => render(element, dom)); | |
parentDom.appendChild(dom); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment