jackfranklin / gulp-load-plugins

Automatically load in gulp plugins
https://github.com/jackfranklin/gulp-load-plugins
MIT License
757 stars 55 forks source link

Return object instead of extending #4

Closed yocontra closed 10 years ago

yocontra commented 10 years ago

Why do

var gulp = require("gulp");
var gulpLoadTasks = require("gulp-load-tasks");

var tasks = {};
gulpLoadTasks(tasks);

When instead you could do this

var gulp = require("gulp");
var gulpLoadTasks = require("gulp-load-tasks");

var tasks = gulpLoadTasks();

It seems more idiomatic to return a new object with all of the tasks on it than to extend them onto an object passed in as an argument.

jackfranklin commented 10 years ago

The reasoning behind was so you didn't have to change your existing Gulp code.

For example, previously if you had:

var jshint = require("gulp-jshint");
// setup Gulp task that calls `jshint`()

And then you swapped to using this plugin and passing in this, you wouldn't have to change your Gulp plugin configuration. If you extend another object, such as tasks, you'd have to change your code to use tasks.jshint().

That was the reasoning - I think it would be nice to make it return an object if no argument is passed, as per your example.

yocontra commented 10 years ago

@jackfranklin Makes sense

jackfranklin commented 10 years ago

@Contra turns out that adding things to this isn't really a good idea - doesn't always work. Hence, am going to update the plugin to take your suggestion into account and do it that way.