@@ -257,37 +257,36 @@ function watch(options, emitter) {
257
257
gaze . add ( watch ) ;
258
258
gaze . on ( 'error' , emitter . emit . bind ( emitter , 'error' ) ) ;
259
259
260
- gaze . on ( 'changed' , function ( file ) {
261
- var files = [ file ] ;
260
+ gaze . on ( 'changed' , updateWatcher ) ;
261
+ gaze . on ( 'added' , updateWatcher ) ;
262
262
263
- // descendents may be added, so we need a new graph
263
+ gaze . on ( 'deleted' , function ( ) {
264
264
graph = buildGraph ( options ) ;
265
- graph . visitAncestors ( file , function ( parent ) {
266
- files . push ( parent ) ;
267
- } ) ;
268
-
269
- // Add children to watcher
270
- graph . visitDescendents ( file , function ( child ) {
271
- if ( watch . indexOf ( child ) === - 1 ) {
272
- watch . push ( child ) ;
273
- gaze . add ( child ) ;
274
- }
275
- } ) ;
276
- files . forEach ( function ( file ) {
277
- if ( path . basename ( file ) [ 0 ] !== '_' ) {
278
- renderFile ( file , options , emitter ) ;
279
- }
280
- } ) ;
281
265
} ) ;
266
+ }
282
267
283
- gaze . on ( 'added' , function ( ) {
284
- graph = buildGraph ( options ) ;
268
+ function updateWatcher ( file ) {
269
+ var files = [ file ] ;
270
+
271
+ // descendents may be added, so we need a new graph
272
+ graph = buildGraph ( options ) ;
273
+ graph . visitAncestors ( file , function ( parent ) {
274
+ files . push ( parent ) ;
285
275
} ) ;
286
276
287
- gaze . on ( 'deleted' , function ( ) {
288
- graph = buildGraph ( options ) ;
277
+ // Add children to watcher
278
+ graph . visitDescendents ( file , function ( child ) {
279
+ if ( watch . indexOf ( child ) === - 1 ) {
280
+ watch . push ( child ) ;
281
+ gaze . add ( child ) ;
282
+ }
289
283
} ) ;
290
- }
284
+ files . forEach ( function ( file ) {
285
+ if ( path . basename ( file ) [ 0 ] !== '_' ) {
286
+ renderFile ( file , options , emitter ) ;
287
+ }
288
+ } ) ;
289
+ } ;
291
290
292
291
/**
293
292
* Run
0 commit comments