Skip to content

Commit

Permalink
use for in instead of for of
Browse files Browse the repository at this point in the history
  • Loading branch information
yisar committed Oct 11, 2019
1 parent 40e3340 commit fcdd82e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions src/dom.js
@@ -1,12 +1,9 @@
import { SVG } from './reconciler'
import { SVG, merge } from './reconciler'

export function updateElement (dom, oldProps, newProps) {
const names = Object.keys({...oldProps, ...newProps})

for (let name of names) {
if (name === "children") {
continue
}
const props = merge(oldProps, newProps)
for (let name in props) {
if (name === 'children') continue

const oldValue = oldProps[name]
const newValue = newProps[name]
Expand All @@ -29,12 +26,11 @@ export function updateElement (dom, oldProps, newProps) {
}

export function createElement (fiber) {
const dom =
fiber.type === 'text'
? document.createTextNode(fiber.value)
: fiber.tag === SVG
? document.createElementNS('http://www.w3.org/2000/svg', fiber.type)
: document.createElement(fiber.type)
const dom = fiber.type === 'text'
? document.createTextNode(fiber.value)
: fiber.tag === SVG
? document.createElementNS('http://www.w3.org/2000/svg', fiber.type)
: document.createElement(fiber.type)
updateElement(dom, {}, fiber.props)
return dom
}
2 changes: 1 addition & 1 deletion src/reconciler.js
Expand Up @@ -219,7 +219,7 @@ function hashfy (arr) {
return out
}

function merge (a, b) {
export function merge (a, b) {
let out = {}
for (const i in a) out[i] = a[i]
for (const i in b) out[i] = b[i]
Expand Down

0 comments on commit fcdd82e

Please sign in to comment.