Created
August 13, 2019 14:05
-
-
Save Tevinthuku/e9543adde6ae4d80dae0d114d12ecf85 to your computer and use it in GitHub Desktop.
the dom utility functions.
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 { TEXT_ELEMENT } from "./element"; | |
/** | |
* @param {HTMLElement} dom - the html element where props get applied to | |
* @param {object} props - consists of both attributes and event listeners. | |
*/ | |
export function updateDomProperties(dom, props) { | |
const isListener = name => name.startsWith("on"); | |
Object.keys(props) | |
.filter(isListener) | |
.forEach(name => { | |
const eventType = name.toLowerCase().substring(2); | |
dom.addEventListener(eventType, props[name]); | |
}); | |
const isAttribute = name => !isListener(name) && name !== "children"; | |
Object.keys(props) | |
.filter(isAttribute) | |
.forEach(name => { | |
dom[name] = props[name]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment