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()
})
}
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,
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
}