From fcdd82ede4cd1c1b1369af06bf90b6e2187fc234 Mon Sep 17 00:00:00 2001 From: 132yse <1533540012@qq.com> Date: Fri, 11 Oct 2019 21:02:52 +0800 Subject: [PATCH] use for in instead of for of --- src/dom.js | 22 +++++++++------------- src/reconciler.js | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/dom.js b/src/dom.js index 1240e4a5..a054d119 100644 --- a/src/dom.js +++ b/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] @@ -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 } diff --git a/src/reconciler.js b/src/reconciler.js index aa1e6753..3ae0bdef 100644 --- a/src/reconciler.js +++ b/src/reconciler.js @@ -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]