javascript - Namespaces in gulp -


i have gulpfile constant path object. 1 of fields array. want iterate through , assign different watch react different tasks. when try assing task in loop:

  for(var = 0; < path.php[i].module.length; i++){   gulp.task('sync-'+path.php[i].module, function(){     return gulp.src(path.php[i].in)       .pipe(newer(path.php[i].out))       .pipe(gulp.dest(path.php[i].out));   }); } 

path.php[i] not defined within anonymous function. reason need because if watch whole folder takes time syncing remote, if preprocessed through plugins "gulp-newer" , "gulp-changed".

the problem asynchronous function call inside loop. when callback fires @ it's final value, every callback called same value i.

you need wrap async function call inside new function, ensure value of i intended in each callback. try pattern:

for(var = 0; < path.php[i].module.length; i++){   (function(i){     gulp.task('sync-'+path.php[i].module, function(){       return gulp.src(path.php[i].in)         .pipe(newer(path.php[i].out))         .pipe(gulp.dest(path.php[i].out));     });   })(i); } 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -