Browse Source

optimize components with no data option

dev
Evan You 8 years ago
parent
commit
0fe431b490
  1. 9
      src/core/instance/state.js
  2. 5
      src/core/observer/index.js

9
src/core/instance/state.js

@ -26,7 +26,11 @@ export function initState (vm: Component) {
const opts = vm.$options
if (opts.props) initProps(vm, opts.props)
if (opts.methods) initMethods(vm, opts.methods)
initData(vm)
if (opts.data) {
initData(vm)
} else {
observe(vm._data = {}, true /* asRootData */)
}
if (opts.computed) initComputed(vm, opts.computed)
if (opts.watch) initWatch(vm, opts.watch)
}
@ -96,8 +100,7 @@ function initData (vm: Component) {
}
}
// observe data
observe(data)
data.__ob__ && data.__ob__.vmCount++
observe(data, true /* asRootData */)
}
const computedSharedDefinition = {

5
src/core/observer/index.js

@ -103,7 +103,7 @@ function copyAugment (target: Object, src: Object, keys: Array<string>) {
* returns the new observer if successfully observed,
* or the existing observer if the value already has one.
*/
export function observe (value: any): Observer | void {
export function observe (value: any, asRootData: ?boolean): Observer | void {
if (!isObject(value)) {
return
}
@ -119,6 +119,9 @@ export function observe (value: any): Observer | void {
) {
ob = new Observer(value)
}
if (asRootData && ob) {
ob.vmCount++
}
return ob
}

Loading…
Cancel
Save