This commit is contained in:
Evan You 2016-04-16 00:15:12 -04:00
parent 61a5249a0e
commit af1f1d349f
3 changed files with 11 additions and 10 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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 }