@@ -245,23 +245,11 @@ function watch(options, emitter) {
245
245
return graph ;
246
246
} ;
247
247
248
- var watch = [ ] ;
249
- var graph = buildGraph ( options ) ;
250
-
251
- // Add all files to watch list
252
- for ( var i in graph . index ) {
253
- watch . push ( i ) ;
254
- }
255
-
256
- var gaze = new Gaze ( ) ;
257
- gaze . add ( watch ) ;
258
- gaze . on ( 'error' , emitter . emit . bind ( emitter , 'error' ) ) ;
259
-
260
- gaze . on ( 'changed' , function ( file ) {
248
+ var updateWatcher = function ( file ) {
249
+ var graph = buildGraph ( options ) ;
261
250
var files = [ file ] ;
262
251
263
252
// descendents may be added, so we need a new graph
264
- graph = buildGraph ( options ) ;
265
253
graph . visitAncestors ( file , function ( parent ) {
266
254
files . push ( parent ) ;
267
255
} ) ;
@@ -278,10 +266,25 @@ function watch(options, emitter) {
278
266
renderFile ( file , options , emitter ) ;
279
267
}
280
268
} ) ;
281
- } ) ;
269
+ } ;
282
270
283
- gaze . on ( 'added' , function ( ) {
284
- graph = buildGraph ( options ) ;
271
+ var watch = [ ] ;
272
+ var graph = buildGraph ( options ) ;
273
+
274
+ // Add all files to watch list
275
+ for ( var i in graph . index ) {
276
+ watch . push ( i ) ;
277
+ }
278
+
279
+ var gaze = new Gaze ( ) ;
280
+ gaze . add ( watch ) ;
281
+ gaze . on ( 'error' , emitter . emit . bind ( emitter , 'error' ) ) ;
282
+
283
+ gaze . on ( 'changed' , function ( file ) {
284
+ updateWatcher ( file ) ;
285
+ } ) ;
286
+ gaze . on ( 'added' , function ( file ) {
287
+ updateWatcher ( file ) ;
285
288
} ) ;
286
289
287
290
gaze . on ( 'deleted' , function ( ) {
0 commit comments