Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commita2cd412

Browse files
committed
refactor: observerState
1 parent318f29f commita2cd412

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

‎src/core/instance/inject.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*@flow */
22

3-
import{warn,hasSymbol}from'../util/index'
4-
import{defineReactive,observerState}from'../observer/index'
53
import{hasOwn}from'shared/util'
4+
import{warn,hasSymbol}from'../util/index'
5+
import{defineReactive,toggleObserving}from'../observer/index'
66

77
exportfunctioninitProvide(vm:Component){
88
constprovide=vm.$options.provide
@@ -16,7 +16,7 @@ export function initProvide (vm: Component) {
1616
exportfunctioninitInjections(vm:Component){
1717
constresult=resolveInject(vm.$options.inject,vm)
1818
if(result){
19-
observerState.shouldConvert=false
19+
toggleObserving(false)
2020
Object.keys(result).forEach(key=>{
2121
/* istanbul ignore else */
2222
if(process.env.NODE_ENV!=='production'){
@@ -32,7 +32,7 @@ export function initInjections (vm: Component) {
3232
defineReactive(vm,key,result[key])
3333
}
3434
})
35-
observerState.shouldConvert=true
35+
toggleObserving(true)
3636
}
3737
}
3838

‎src/core/instance/lifecycle.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import config from '../config'
44
importWatcherfrom'../observer/watcher'
55
import{mark,measure}from'../util/perf'
66
import{createEmptyVNode}from'../vdom/vnode'
7-
import{observerState}from'../observer/index'
87
import{updateComponentListeners}from'./events'
98
import{resolveSlots}from'./render-helpers/resolve-slots'
9+
import{toggleObserving}from'../observer/index'
1010
import{pushTarget,popTarget}from'../observer/dep'
1111

1212
import{
@@ -245,14 +245,15 @@ export function updateChildComponent (
245245

246246
// update props
247247
if(propsData&&vm.$options.props){
248-
observerState.shouldConvert=false
248+
toggleObserving(false)
249249
constprops=vm._props
250250
constpropKeys=vm.$options._propKeys||[]
251251
for(leti=0;i<propKeys.length;i++){
252252
constkey=propKeys[i]
253-
props[key]=validateProp(key,vm.$options.props,propsData,vm)
253+
constpropOptions:any=vm.$options.props// wtf flow?
254+
props[key]=validateProp(key,propOptions,propsData,vm)
254255
}
255-
observerState.shouldConvert=true
256+
toggleObserving(true)
256257
// keep a copy of raw propsData
257258
vm.$options.propsData=propsData
258259
}

‎src/core/instance/state.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99
set,
1010
del,
1111
observe,
12-
observerState,
13-
defineReactive
12+
defineReactive,
13+
toggleObserving
1414
}from'../observer/index'
1515

1616
import{
@@ -69,7 +69,9 @@ function initProps (vm: Component, propsOptions: Object) {
6969
constkeys=vm.$options._propKeys=[]
7070
constisRoot=!vm.$parent
7171
// root instance props should be converted
72-
observerState.shouldConvert=isRoot
72+
if(!isRoot){
73+
toggleObserving(false)
74+
}
7375
for(constkeyinpropsOptions){
7476
keys.push(key)
7577
constvalue=validateProp(key,propsOptions,propsData,vm)
@@ -104,7 +106,7 @@ function initProps (vm: Component, propsOptions: Object) {
104106
proxy(vm,`_props`,key)
105107
}
106108
}
107-
observerState.shouldConvert=true
109+
toggleObserving(true)
108110
}
109111

110112
functioninitData(vm:Component){

‎src/core/observer/index.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import {
1717
constarrayKeys=Object.getOwnPropertyNames(arrayMethods)
1818

1919
/**
20-
* By default, when a reactive property is set, the new value is
21-
* also converted to become reactive. However when passing down props,
22-
* we don't want to force conversion because the value may be a nested value
23-
* under a frozen data structure. Converting it would defeat the optimization.
20+
* In some cases we may want to disable observation inside a component's
21+
* update computation.
2422
*/
25-
exportconstobserverState={
26-
shouldConvert:true
23+
exportletshouldObserve:boolean=true
24+
25+
exportfunctiontoggleObserving(value:boolean){
26+
shouldObserve=value
2727
}
2828

2929
/**
@@ -112,7 +112,7 @@ export function observe (value: any, asRootData: ?boolean): Observer | void {
112112
if(hasOwn(value,'__ob__')&&value.__ob__instanceofObserver){
113113
ob=value.__ob__
114114
}elseif(
115-
observerState.shouldConvert&&
115+
shouldObserve&&
116116
!isServerRendering()&&
117117
(Array.isArray(value)||isPlainObject(value))&&
118118
Object.isExtensible(value)&&

‎src/core/util/props.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*@flow */
22

33
import{warn}from'./debug'
4-
import{observe,observerState}from'../observer/index'
4+
import{observe,toggleObserving,shouldObserve}from'../observer/index'
55
import{
66
hasOwn,
77
isObject,
@@ -40,10 +40,10 @@ export function validateProp (
4040
value=getPropDefaultValue(vm,prop,key)
4141
// since the default value is a fresh copy,
4242
// make sure to observe it.
43-
constprevShouldConvert=observerState.shouldConvert
44-
observerState.shouldConvert=true
43+
constprevShouldObserve=shouldObserve
44+
toggleObserving(true)
4545
observe(value)
46-
observerState.shouldConvert=prevShouldConvert
46+
toggleObserving(prevShouldObserve)
4747
}
4848
if(
4949
process.env.NODE_ENV!=='production'&&

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp