File tree Expand file tree Collapse file tree 2 files changed +13
-18
lines changed Expand file tree Collapse file tree 2 files changed +13
-18
lines changed Original file line number Diff line number Diff line change @@ -46,3 +46,13 @@ export default class Dep {
46
46
// this is globally unique because there could be only one
47
47
// watcher being evaluated at any time.
48
48
Dep . target = null
49
+ const targetStack = [ ]
50
+
51
+ export function pushTarget ( _target : Watcher ) {
52
+ if ( Dep . target ) targetStack . push ( Dep . target )
53
+ Dep . target = _target
54
+ }
55
+
56
+ export function popTarget ( ) {
57
+ Dep . target = targetStack . pop ( )
58
+ }
Original file line number Diff line number Diff line change 1
1
/* @flow */
2
2
3
3
import config from '../config'
4
- import Dep from './dep'
4
+ import Dep , { pushTarget , popTarget } from './dep'
5
5
import { queueWatcher } from './scheduler'
6
6
import {
7
7
warn ,
@@ -83,7 +83,7 @@ export default class Watcher {
83
83
* Evaluate the getter, and re-collect dependencies.
84
84
*/
85
85
get ( ) {
86
- this . pushTarget ( )
86
+ pushTarget ( this )
87
87
let value : any
88
88
try {
89
89
value = this . getter . call ( this . vm , this . vm )
@@ -116,26 +116,11 @@ export default class Watcher {
116
116
if ( this . deep ) {
117
117
traverse ( value )
118
118
}
119
- this . popTarget ( )
119
+ popTarget ( )
120
120
this . cleanupDeps ( )
121
121
return value
122
122
}
123
123
124
- /**
125
- * Set this watcher as the active dep target
126
- */
127
- pushTarget ( ) {
128
- if ( Dep . target ) targetStack . push ( Dep . target )
129
- Dep . target = this
130
- }
131
-
132
- /**
133
- * Restore previous dep target
134
- */
135
- popTarget ( ) {
136
- Dep . target = targetStack . pop ( )
137
- }
138
-
139
124
/**
140
125
* Add a dependency to this directive.
141
126
*/
You can’t perform that action at this time.
0 commit comments