Browse Source

only diff data if props did not change

dev
Evan You 9 years ago
parent
commit
d3c64fa6a6
  1. 18
      src/runtime/instance/render.js
  2. 1
      src/runtime/util/options.js

18
src/runtime/instance/render.js

@ -55,13 +55,14 @@ export function renderMixin (Vue) {
this.$options._renderChildren = children
// update props and listeners
if (parentData) {
updateEvents(this, parentData, oldParentData)
// 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)
const propsChanged = updateProps(this, parentData)
// diff parent data (attrs on the placeholder) and queue update
// if anything changed
if (parentDataChanged(parentData, oldParentData)) {
// if anything changed. only do this if props didn't change, because
// if props changed then an update has already been queued.
if (!propsChanged && parentDataChanged(parentData, oldParentData)) {
this.$forceUpdate()
}
}
@ -213,15 +214,22 @@ function mergeParentData (vm, data, parentData) {
}
function updateProps (vm, data) {
let changed = false
if (data.attrs || data.props) {
let keys = vm.$options.propKeys
if (keys) {
for (let i = 0; i < keys.length; i++) {
let key = keys[i]
vm[key] = getPropValue(data, key, vm)
let oldVal = vm[key]
let newVal = getPropValue(data, key, vm)
if (oldVal !== newVal) {
vm[key] = newVal
changed = true
}
}
}
}
return changed
}
function updateEvents (vm, data, oldData) {

1
src/runtime/util/options.js

@ -266,7 +266,6 @@ function guardProps (options) {
: { type: val }
}
}
console.log(res)
options.props = res
}

Loading…
Cancel
Save