Skip to content

Instantly share code, notes, and snippets.

@Tevinthuku
Last active August 13, 2019 19:10
Show Gist options
  • Save Tevinthuku/f23bfd13f2d723e266d2b91560c87c63 to your computer and use it in GitHub Desktop.
Save Tevinthuku/f23bfd13f2d723e266d2b91560c87c63 to your computer and use it in GitHub Desktop.
Code related to reconciliation
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