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 {
4646// this is globally unique because there could be only one
4747// watcher being evaluated at any time.
4848Dep . 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 11/* @flow */
22
33import config from '../config'
4- import Dep from './dep'
4+ import Dep , { pushTarget , popTarget } from './dep'
55import { queueWatcher } from './scheduler'
66import {
77 warn ,
@@ -83,7 +83,7 @@ export default class Watcher {
8383 * Evaluate the getter, and re-collect dependencies.
8484 */
8585 get ( ) {
86- this . pushTarget ( )
86+ pushTarget ( this )
8787 let value : any
8888 try {
8989 value = this . getter . call ( this . vm , this . vm )
@@ -116,26 +116,11 @@ export default class Watcher {
116116 if ( this . deep ) {
117117 traverse ( value )
118118 }
119- this . popTarget ( )
119+ popTarget ( )
120120 this . cleanupDeps ( )
121121 return value
122122 }
123123
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-
139124 /**
140125 * Add a dependency to this directive.
141126 */
You can’t perform that action at this time.
0 commit comments