mirror of
https://github.com/vuejs/vue.git
synced 2024-11-22 04:39:46 +00:00
make prop bindings immutable
This commit is contained in:
parent
7c3fa3c2bb
commit
56073ca853
@ -23,7 +23,7 @@ Vue.prototype.$mount = function (el) {
|
||||
} else {
|
||||
template = getOuterHTML(query(el))
|
||||
}
|
||||
options.render = new Function(compile(template, config.preserveWhiteSpace))
|
||||
options.render = new Function(compile(template, config.preserveWhitespace))
|
||||
}
|
||||
mount.call(this, el)
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ export default {
|
||||
* Preserve whitespaces between elements.
|
||||
*/
|
||||
|
||||
preserveWhiteSpace: true,
|
||||
preserveWhitespace: true,
|
||||
|
||||
/**
|
||||
* Whether to suppress warnings.
|
||||
|
@ -77,14 +77,16 @@ export function renderMixin (Vue) {
|
||||
this.$forceUpdate()
|
||||
return
|
||||
}
|
||||
// set props. because props are reactive,
|
||||
// if any of them has changed it will trigger an update.
|
||||
// set props if they have changed.
|
||||
const attrs = data && data.attrs
|
||||
if (attrs) {
|
||||
for (let key in this.$options.props) {
|
||||
this[key] = hasOwn(attrs, key)
|
||||
let newVal = hasOwn(attrs, key)
|
||||
? attrs[key]
|
||||
: attrs[hyphenate(key)]
|
||||
if (this[key] !== newVal) {
|
||||
this[key] = newVal
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,7 +101,6 @@ export function renderMixin (Vue) {
|
||||
mergeParentData(this, data, parentData)
|
||||
}
|
||||
renderState.activeInstance = prev
|
||||
console.log(vnode)
|
||||
return vnode
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ function initProps (vm) {
|
||||
if (props) {
|
||||
withoutConversion(() => {
|
||||
for (let key in props) {
|
||||
defineReactive(vm, key, attrs[key])
|
||||
defineReactive(vm, key, attrs[key], true /* immutable */)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -6,7 +6,8 @@ import {
|
||||
isObject,
|
||||
isPlainObject,
|
||||
hasProto,
|
||||
hasOwn
|
||||
hasOwn,
|
||||
warn
|
||||
} from '../util/index'
|
||||
|
||||
const arrayKeys = Object.getOwnPropertyNames(arrayMethods)
|
||||
@ -192,7 +193,7 @@ export function observe (value, vm) {
|
||||
* @param {*} val
|
||||
*/
|
||||
|
||||
export function defineReactive (obj, key, val) {
|
||||
export function defineReactive (obj, key, val, immutable) {
|
||||
var dep = new Dep()
|
||||
|
||||
var property = Object.getOwnPropertyDescriptor(obj, key)
|
||||
@ -224,18 +225,24 @@ export function defineReactive (obj, key, val) {
|
||||
}
|
||||
return value
|
||||
},
|
||||
set: function reactiveSetter (newVal) {
|
||||
var value = getter ? getter.call(obj) : val
|
||||
if (newVal === value) {
|
||||
return
|
||||
set: immutable
|
||||
? function immutableSetter () {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
warn(`property "${key}" is immutable.`)
|
||||
}
|
||||
}
|
||||
if (setter) {
|
||||
setter.call(obj, newVal)
|
||||
} else {
|
||||
val = newVal
|
||||
: function reactiveSetter (newVal) {
|
||||
var value = getter ? getter.call(obj) : val
|
||||
if (newVal === value) {
|
||||
return
|
||||
}
|
||||
if (setter) {
|
||||
setter.call(obj, newVal)
|
||||
} else {
|
||||
val = newVal
|
||||
}
|
||||
childOb = observe(newVal)
|
||||
dep.notify()
|
||||
}
|
||||
childOb = observe(newVal)
|
||||
dep.notify()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user