Browse Source

update props checking

dev
Evan You 9 years ago
parent
commit
c12ddd9ab9
  1. 41
      src/runtime/instance/render.js

41
src/runtime/instance/render.js

@ -40,8 +40,8 @@ function resolveSlots (vm, children) {
}
function mergeParentAttrs (vm, data, parentData) {
const props = vm.$options.props
if (parentData.attrs) {
const props = vm.$options.props
const attrs = data.attrs || (data.attrs = [])
for (let key in parentData.attrs) {
if (!hasOwn(props, key)) {
@ -49,6 +49,9 @@ function mergeParentAttrs (vm, data, parentData) {
}
}
}
if (parentData.props) {
}
}
function mergeParentDirectives (vm, data, parentData) {
@ -65,6 +68,30 @@ function updateParentCallbacks (vm, data, parentData) {
}
}
function updateProps (vm, data) {
const attrs = data.attrs
const props = data.props
if (attrs || props) {
for (let key in vm.$options.props) {
let altKey = hyphenate(key)
let newVal =
getPropValue(attrs, key, altKey) ||
getPropValue(props, key, altKey)
if (vm[key] !== newVal) {
vm[key] = newVal
}
}
}
}
function getPropValue (hash, key, altKey) {
return hash
? hasOwn(hash, key)
? hash[key]
: hash[altKey]
: undefined
}
export function renderMixin (Vue) {
// shorthands used in render functions
Vue.prototype.__h__ = createElement
@ -92,16 +119,8 @@ export function renderMixin (Vue) {
return
}
// set props - this will trigger update if any of them changed
const attrs = data && data.attrs
if (attrs) {
for (let key in this.$options.props) {
let newVal = hasOwn(attrs, key)
? attrs[key]
: attrs[hyphenate(key)]
if (this[key] !== newVal) {
this[key] = newVal
}
}
if (data) {
updateProps(this, data)
}
}

Loading…
Cancel
Save