@@ -229,22 +229,6 @@ function getOptions(args, options) {
229
229
*/
230
230
231
231
function watch ( options , emitter ) {
232
- var buildGraph = function ( options ) {
233
- var graph ;
234
- var graphOptions = {
235
- loadPaths : options . includePath ,
236
- extensions : [ 'scss' , 'sass' , 'css' ]
237
- } ;
238
-
239
- if ( options . directory ) {
240
- graph = grapher . parseDir ( options . directory , graphOptions ) ;
241
- } else {
242
- graph = grapher . parseFile ( options . src , graphOptions ) ;
243
- }
244
-
245
- return graph ;
246
- } ;
247
-
248
232
var watch = [ ] ;
249
233
var graph = buildGraph ( options ) ;
250
234
@@ -258,34 +242,53 @@ function watch(options, emitter) {
258
242
gaze . on ( 'error' , emitter . emit . bind ( emitter , 'error' ) ) ;
259
243
260
244
gaze . on ( 'changed' , function ( file ) {
261
- var files = [ file ] ;
245
+ updateWatcher ( file , graph , gaze , options ) ;
246
+ } ) ;
247
+ gaze . on ( 'added' , function ( file ) {
248
+ updateWatcher ( file , graph , gaze , options ) ;
249
+ } ) ;
262
250
263
- // descendents may be added, so we need a new graph
251
+ gaze . on ( 'deleted' , function ( ) {
264
252
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
253
} ) ;
254
+ }
282
255
283
- gaze . on ( 'added' , function ( ) {
284
- graph = buildGraph ( options ) ;
256
+ function buildGraph ( options ) {
257
+ var graph ;
258
+ var graphOptions = {
259
+ loadPaths : options . includePath ,
260
+ extensions : [ 'scss' , 'sass' , 'css' ]
261
+ } ;
262
+
263
+ if ( options . directory ) {
264
+ graph = grapher . parseDir ( options . directory , graphOptions ) ;
265
+ } else {
266
+ graph = grapher . parseFile ( options . src , graphOptions ) ;
267
+ }
268
+
269
+ return graph ;
270
+ }
271
+
272
+ function updateWatcher ( file , graph , gaze ) {
273
+ var files = [ file ] ;
274
+
275
+ // descendents may be added, so we need a new graph
276
+ graph = buildGraph ( options ) ;
277
+ graph . visitAncestors ( file , function ( parent ) {
278
+ files . push ( parent ) ;
285
279
} ) ;
286
280
287
- gaze . on ( 'deleted' , function ( ) {
288
- graph = buildGraph ( options ) ;
281
+ // Add children to watcher
282
+ graph . visitDescendents ( file , function ( child ) {
283
+ if ( watch . indexOf ( child ) === - 1 ) {
284
+ watch . push ( child ) ;
285
+ gaze . add ( child ) ;
286
+ }
287
+ } ) ;
288
+ files . forEach ( function ( file ) {
289
+ if ( path . basename ( file ) [ 0 ] !== '_' ) {
290
+ renderFile ( file , options , emitter ) ;
291
+ }
289
292
} ) ;
290
293
}
291
294
0 commit comments