7
7
warn ,
8
8
isArray ,
9
9
isObject ,
10
- nextTick
10
+ nextTick ,
11
+ _Set as Set
11
12
} from './util/index'
12
13
13
14
let uid = 0
@@ -47,8 +48,8 @@ export default function Watcher (vm, expOrFn, cb, options) {
47
48
this . dirty = this . lazy // for lazy watchers
48
49
this . deps = [ ]
49
50
this . newDeps = [ ]
50
- this . depIds = Object . create ( null )
51
- this . newDepIds = null
51
+ this . depIds = new Set ( )
52
+ this . newDepIds = new Set ( )
52
53
this . prevError = null // for async error stacks
53
54
// parse expression for getter/setter
54
55
if ( isFn ) {
@@ -163,8 +164,6 @@ Watcher.prototype.set = function (value) {
163
164
164
165
Watcher . prototype . beforeGet = function ( ) {
165
166
Dep . target = this
166
- this . newDepIds = Object . create ( null )
167
- this . newDeps . length = 0
168
167
}
169
168
170
169
/**
@@ -175,10 +174,10 @@ Watcher.prototype.beforeGet = function () {
175
174
176
175
Watcher . prototype . addDep = function ( dep ) {
177
176
var id = dep . id
178
- if ( ! this . newDepIds [ id ] ) {
179
- this . newDepIds [ id ] = true
177
+ if ( ! this . newDepIds . has ( id ) ) {
178
+ this . newDepIds . add ( id )
180
179
this . newDeps . push ( dep )
181
- if ( ! this . depIds [ id ] ) {
180
+ if ( ! this . depIds . has ( id ) ) {
182
181
dep . addSub ( this )
183
182
}
184
183
}
@@ -193,14 +192,18 @@ Watcher.prototype.afterGet = function () {
193
192
var i = this . deps . length
194
193
while ( i -- ) {
195
194
var dep = this . deps [ i ]
196
- if ( ! this . newDepIds [ dep . id ] ) {
195
+ if ( ! this . newDepIds . has ( dep . id ) ) {
197
196
dep . removeSub ( this )
198
197
}
199
198
}
199
+ var tmp = this . depIds
200
200
this . depIds = this . newDepIds
201
- var tmp = this . deps
201
+ this . newDepIds = tmp
202
+ this . newDepIds . clear ( )
203
+ tmp = this . deps
202
204
this . deps = this . newDeps
203
205
this . newDeps = tmp
206
+ this . newDeps . length = 0
204
207
}
205
208
206
209
/**
0 commit comments