@@ -13,6 +13,7 @@ const watchEventSource = require("./watchEventSource");
13
13
let EXISTANCE_ONLY_TIME_ENTRY ; // lazy required
14
14
15
15
const EMPTY_ARRAY = [ ] ;
16
+ const EMPTY_OPTIONS = { } ;
16
17
17
18
function addWatchersToSet ( watchers , set ) {
18
19
for ( const w of watchers ) {
@@ -64,11 +65,12 @@ const cachedNormalizeOptions = options => {
64
65
class Watchpack extends EventEmitter {
65
66
constructor ( options ) {
66
67
super ( ) ;
67
- if ( ! options ) options = { } ;
68
- if ( typeof options . aggregateTimeout !== "number" ) {
69
- options . aggregateTimeout = 200 ;
70
- }
68
+ if ( ! options ) options = EMPTY_OPTIONS ;
71
69
this . options = options ;
70
+ this . aggregateTimeout =
71
+ typeof options . aggregateTimeout === "number"
72
+ ? options . aggregateTimeout
73
+ : 200 ;
72
74
this . watcherOptions = cachedNormalizeOptions ( options ) ;
73
75
this . watcherManager = getWatcherManager ( this . watcherOptions ) ;
74
76
this . fileWatchers = new Map ( ) ;
@@ -77,7 +79,7 @@ class Watchpack extends EventEmitter {
77
79
this . paused = false ;
78
80
this . aggregatedChanges = new Set ( ) ;
79
81
this . aggregatedRemovals = new Set ( ) ;
80
- this . aggregateTimeout = 0 ;
82
+ this . aggregateTimer = undefined ;
81
83
this . _onTimeout = this . _onTimeout . bind ( this ) ;
82
84
}
83
85
@@ -249,7 +251,7 @@ class Watchpack extends EventEmitter {
249
251
250
252
close ( ) {
251
253
this . paused = true ;
252
- if ( this . aggregateTimeout ) clearTimeout ( this . aggregateTimeout ) ;
254
+ if ( this . aggregateTimer ) clearTimeout ( this . aggregateTimer ) ;
253
255
for ( const w of this . fileWatchers . values ( ) ) w . close ( ) ;
254
256
for ( const w of this . directoryWatchers . values ( ) ) w . close ( ) ;
255
257
this . fileWatchers . clear ( ) ;
@@ -258,7 +260,7 @@ class Watchpack extends EventEmitter {
258
260
259
261
pause ( ) {
260
262
this . paused = true ;
261
- if ( this . aggregateTimeout ) clearTimeout ( this . aggregateTimeout ) ;
263
+ if ( this . aggregateTimer ) clearTimeout ( this . aggregateTimer ) ;
262
264
}
263
265
264
266
getTimes ( ) {
@@ -344,30 +346,24 @@ class Watchpack extends EventEmitter {
344
346
file = file || item ;
345
347
if ( this . paused ) return ;
346
348
this . emit ( "change" , file , mtime , type ) ;
347
- if ( this . aggregateTimeout ) clearTimeout ( this . aggregateTimeout ) ;
349
+ if ( this . aggregateTimer ) clearTimeout ( this . aggregateTimer ) ;
348
350
this . aggregatedRemovals . delete ( item ) ;
349
351
this . aggregatedChanges . add ( item ) ;
350
- this . aggregateTimeout = setTimeout (
351
- this . _onTimeout ,
352
- this . options . aggregateTimeout
353
- ) ;
352
+ this . aggregateTimer = setTimeout ( this . _onTimeout , this . aggregateTimeout ) ;
354
353
}
355
354
356
355
_onRemove ( item , file , type ) {
357
356
file = file || item ;
358
357
if ( this . paused ) return ;
359
358
this . emit ( "remove" , file , type ) ;
360
- if ( this . aggregateTimeout ) clearTimeout ( this . aggregateTimeout ) ;
359
+ if ( this . aggregateTimer ) clearTimeout ( this . aggregateTimer ) ;
361
360
this . aggregatedChanges . delete ( item ) ;
362
361
this . aggregatedRemovals . add ( item ) ;
363
- this . aggregateTimeout = setTimeout (
364
- this . _onTimeout ,
365
- this . options . aggregateTimeout
366
- ) ;
362
+ this . aggregateTimer = setTimeout ( this . _onTimeout , this . aggregateTimeout ) ;
367
363
}
368
364
369
365
_onTimeout ( ) {
370
- this . aggregateTimeout = 0 ;
366
+ this . aggregateTimer = undefined ;
371
367
const changes = this . aggregatedChanges ;
372
368
const removals = this . aggregatedRemovals ;
373
369
this . aggregatedChanges = new Set ( ) ;
0 commit comments