Evan You 10 years ago
parent
commit
af1f1d349f
3 changed files with 11 additions and 10 deletions
  1. 1 1
      src/compiler/codegen/index.js
  2. 8 7
      src/runtime/instance/render.js
  3. 2 2
      src/runtime/vdom/index.js

+ 1 - 1
src/compiler/codegen/index.js

@@ -102,7 +102,7 @@ function genChildren (el, asThunk) {
   }
   const code = '[' + el.children.map(genNode).join(',') + ']'
   return asThunk
-    ? `_withContext(function(){return ${code}})`
+    ? `_renderWithContext(function(){return ${code}})`
     : code
 }
 

+ 8 - 7
src/runtime/instance/render.js

@@ -1,6 +1,6 @@
 import Watcher from '../observer/watcher'
 import { extend, query, resolveAsset, hasOwn, isArray, isObject } from '../util/index'
-import { createElement, patch, updateListeners } from '../vdom/index'
+import { createElement, patch, updateListeners, flatten } from '../vdom/index'
 import { callHook } from './lifecycle'
 import { getPropValue } from './state'
 
@@ -48,13 +48,14 @@ export function renderMixin (Vue) {
     this.$options._renderChildren = children
     // update props and listeners
     if (parentData) {
+      // if any prop has changed it would trigger and queue an update,
+      // but if no props changed, nothing happens
       updateProps(this, parentData)
       updateEvents(this, parentData, oldParentData)
     }
-    // for now, if the component has content it always updates
-    // because we don't know whether the children have changed.
-    // need to optimize in the future.
-    if (children || diffParentData(parentData, oldParentData)) {
+    // diff parent data (attrs on the placeholder) and queue update
+    // if anything changed
+    if (diffParentData(parentData, oldParentData)) {
       this.$forceUpdate()
     }
   }
@@ -64,11 +65,11 @@ export function renderMixin (Vue) {
    * This is used to wrap all children thunks in codegen.
    */
 
-  Vue.prototype._withContext = function (fn) {
+  Vue.prototype._renderWithContext = function (fn) {
     return () => {
       const prev = renderState.context
       renderState.context = this
-      const children = fn()
+      const children = flatten(fn())
       renderState.context = prev
       return children
     }

+ 2 - 2
src/runtime/vdom/index.js

@@ -5,7 +5,7 @@
  */
 
 import createPatchFunction from './patch'
-import createElement from './create-element'
+import createElement, { flatten } from './create-element'
 import classes from './modules/class'
 import style from './modules/style'
 import props from './modules/props'
@@ -22,4 +22,4 @@ const patch = createPatchFunction([
   directives
 ])
 
-export { patch, createElement, updateListeners }
+export { patch, createElement, updateListeners, flatten }