From d1ff54a2d389ce86a3ef2ac12d073da22a734079 Mon Sep 17 00:00:00 2001 From: 1921622004 <1921622004qwer@gmail.com> Date: Tue, 6 Nov 2018 22:36:32 +0800 Subject: [PATCH 1/3] render array --- packages/omi/src/vdom/diff.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/omi/src/vdom/diff.js b/packages/omi/src/vdom/diff.js index b9e43cd8f..1a10a9886 100644 --- a/packages/omi/src/vdom/diff.js +++ b/packages/omi/src/vdom/diff.js @@ -36,10 +36,13 @@ export function diff(dom, vnode, context, mountAll, parent, componentRoot) { ret = [] let parentNode = null if (isArray(dom)) { - parentNode = dom[0].parentNode - dom.forEach(function(item, index) { - ret.push(idiff(item, vnode[index], context, mountAll, componentRoot)) - }) + var domLength = dom.length; + var vnodeLength = vnode.length; + var maxLength = domLength >= vnodeLength ? domLength : vnodeLength; + parentNode = dom[0].parentNode; + for(var i = 0; i < maxLength ; i++){ + ret.push(idiff(dom[i],vnode[i],context,mountAll,componentRoot)); + } } else { vnode.forEach(function(item) { ret.push(idiff(dom, item, context, mountAll, componentRoot)) @@ -71,7 +74,7 @@ export function diff(dom, vnode, context, mountAll, parent, componentRoot) { /** Internals of `diff()`, separated to allow bypassing diffLevel / mount flushing. */ function idiff(dom, vnode, context, mountAll, componentRoot) { - if (dom && dom.props) { + if (dom && vnode && dom.props) { dom.props.children = vnode.children } let out = dom, From f25946689ac4117d0d6bc9c7d354b0734626e7c0 Mon Sep 17 00:00:00 2001 From: 1921622004 <1921622004qwer@gmail.com> Date: Wed, 7 Nov 2018 21:49:42 +0800 Subject: [PATCH 2/3] fix bug --- packages/omi/src/we-element.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/omi/src/we-element.js b/packages/omi/src/we-element.js index b1126fc15..4c44e55da 100644 --- a/packages/omi/src/we-element.js +++ b/packages/omi/src/we-element.js @@ -27,7 +27,7 @@ export default class WeElement extends HTMLElement { } } - this.install() + !this._isInstalled && this.install() let shadowRoot if (!this.shadowRoot) { shadowRoot = this.attachShadow({ @@ -42,7 +42,7 @@ export default class WeElement extends HTMLElement { } this.css && shadowRoot.appendChild(cssToDom(this.css())) - this.beforeRender() + !this._isInstalled && this.beforeRender() options.afterInstall && options.afterInstall(this) if (this.constructor.observe) { proxyUpdate(this) @@ -65,7 +65,7 @@ export default class WeElement extends HTMLElement { } else { shadowRoot.appendChild(this.host) } - this.installed() + !this._isInstalled && this.installed() this._isInstalled = true } From 208b4cc03e6cc25006ce6215732dc9089ca52e47 Mon Sep 17 00:00:00 2001 From: 1921622004 <1921622004qwer@gmail.com> Date: Wed, 7 Nov 2018 21:52:31 +0800 Subject: [PATCH 3/3] update example --- packages/omi/examples/render-array/main.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/omi/examples/render-array/main.js b/packages/omi/examples/render-array/main.js index 854f7ef11..cba883de0 100644 --- a/packages/omi/examples/render-array/main.js +++ b/packages/omi/examples/render-array/main.js @@ -3,23 +3,27 @@ import { tag, render, WeElement } from '../../src/omi' @tag('hello-element') class HelloElement extends WeElement { render(props) { - const { count } = props - return [
Hello
,
Element
,
{count}
] + const { count, num } = props + return [
Hello
,
Element
,
{count}
,
{num}
] } } @tag('my-app') class MyApp extends WeElement { data = { - count: 1 + count: 1, + list:[0] } render() { - return [, ,
abc
] + this.data.map((item,index) => { + return + }) } installed() { - setInterval(() => { - this.data.count++ + setTimeout(() => { + this.data.count++; + this.data.list.push(1); this.update() }) }