+60
-4
@@ -28,3 +28,3 @@ /* | ||
| Tapable.prototype.applyPluginsWaterfall = function applyPlugins(name, init) { | ||
| Tapable.prototype.applyPluginsWaterfall = function applyPluginsWaterfall(name, init) { | ||
| if(!this._plugins[name]) return init; | ||
@@ -51,2 +51,13 @@ var args = Array.prototype.slice.call(arguments, 2); | ||
| Tapable.prototype.applyPluginsBailResult1 = function applyPluginsBailResult1(name, param) { | ||
| if(!this._plugins[name]) return; | ||
| var plugins = this._plugins[name]; | ||
| for(var i = 0; i < plugins.length; i++) { | ||
| var result = plugins[i].call(this, param); | ||
| if(typeof result !== "undefined") { | ||
| return result; | ||
| } | ||
| } | ||
| }; | ||
| Tapable.prototype.applyPluginsAsyncSeries = Tapable.prototype.applyPluginsAsync = function applyPluginsAsync(name) { | ||
@@ -75,2 +86,3 @@ var args = Array.prototype.slice.call(arguments, 1); | ||
| var i = 0; | ||
| var _this = this; | ||
| args.push(copyProperties(callback, function next() { | ||
@@ -82,7 +94,22 @@ if(arguments.length > 0) return callback.apply(null, arguments); | ||
| } | ||
| plugins[i].apply(this, args); | ||
| }.bind(this))); | ||
| plugins[i].apply(_this, args); | ||
| })); | ||
| plugins[0].apply(this, args); | ||
| }; | ||
| Tapable.prototype.applyPluginsAsyncSeriesBailResult1 = function applyPluginsAsyncSeriesBailResult1(name, param, callback) { | ||
| if(!this._plugins[name] || this._plugins[name].length === 0) return callback(); | ||
| var plugins = this._plugins[name]; | ||
| var i = 0; | ||
| var innerCallback = copyProperties(callback, function next(err, result) { | ||
| if(arguments.length > 0) return callback(err, result); | ||
| i++; | ||
| if(i >= plugins.length) { | ||
| return callback(); | ||
| } | ||
| plugins[i].call(this, param, innerCallback); | ||
| }); | ||
| plugins[0].call(this, param, innerCallback); | ||
| }; | ||
| Tapable.prototype.applyPluginsAsyncWaterfall = function applyPluginsAsyncWaterfall(name, init, callback) { | ||
@@ -92,2 +119,3 @@ if(!this._plugins[name] || this._plugins[name].length === 0) return callback(null, init); | ||
| var i = 0; | ||
| var _this = this; | ||
| var next = copyProperties(callback, function(err, value) { | ||
@@ -99,3 +127,3 @@ if(err) return callback(err); | ||
| } | ||
| plugins[i].call(this, value, next); | ||
| plugins[i].call(_this, value, next); | ||
| }.bind(this)); | ||
@@ -158,3 +186,31 @@ plugins[0].call(this, init, next); | ||
| Tapable.prototype.applyPluginsParallelBailResult1 = function applyPluginsParallelBailResult1(name, param, callback) { | ||
| if(!this._plugins[name] || this._plugins[name].length === 0) return callback(); | ||
| var plugins = this._plugins[name]; | ||
| var currentPos = plugins.length; | ||
| var currentResult; | ||
| var done = []; | ||
| for(var i = 0; i < plugins.length; i++) { | ||
| var innerCallback = (function(i) { | ||
| return copyProperties(callback, function() { | ||
| if(i >= currentPos) return; // ignore | ||
| done.push(i); | ||
| if(arguments.length > 0) { | ||
| currentPos = i + 1; | ||
| done = done.filter(function(item) { | ||
| return item <= i; | ||
| }); | ||
| currentResult = Array.prototype.slice.call(arguments); | ||
| } | ||
| if(done.length === currentPos) { | ||
| callback.apply(null, currentResult); | ||
| currentPos = 0; | ||
| } | ||
| }); | ||
| }(i)); | ||
| plugins[i].call(this, param, innerCallback); | ||
| } | ||
| }; | ||
| Tapable.prototype.plugin = function plugin(name, fn) { | ||
@@ -161,0 +217,0 @@ if(Array.isArray(name)) { |
+1
-1
| { | ||
| "name": "tapable", | ||
| "version": "0.2.2", | ||
| "version": "0.2.3", | ||
| "author": "Tobias Koppers @sokra", | ||
@@ -5,0 +5,0 @@ "description": "Just a little module for plugins.", |
@@ -136,3 +136,3 @@ /* | ||
| [3, "a"], | ||
| [0, "ok", undefined], | ||
| [0, "ok"], | ||
| ]); | ||
@@ -139,0 +139,0 @@ }); |
16579
12.28%344
18.21%