Add copyItemStates tool function

This commit is contained in:
pandamicro
2016-02-17 19:23:31 +08:00
parent eb9693b200
commit 4e765c1731
2 changed files with 23 additions and 6 deletions
+1 -6
View File
@@ -234,12 +234,7 @@ JS.mixin(Downloader.prototype, {
handle: function (item, callback) {
var downloadFunc = this.extMap[item.type] || this.extMap['default'];
downloadFunc(item.src, function (err, result) {
if (err) {
callback && callback(err);
}
else {
callback && callback(null, result);
}
callback && callback(err, result);
});
}
});
+22
View File
@@ -208,6 +208,28 @@ JS.mixin(Pipeline.prototype, {
}
},
/**
* Copy the item states from one source item to all destination items.
* It's quite useful when a pipe generate new items from one source item,
* then you should flowIn these generated items into pipeline,
* but you probably want them to skip all pipes the source item already go through,
* you can achieve it with this API.
*
* For example, an unzip pipe will generate more items, but you won't want them to pass unzip or download pipe again.
* @method copyItemStates
* @param {Object} srcItem The source item
* @param {Array|Object} dstItems A single destination item or an array of destination items
*/
copyItemStates: function (srcItem, dstItems) {
if (!(dstItems instanceof Array)) {
dstItems.states = srcItem.states;
return;
}
for (var i = 0; i < dstItems.length; ++i) {
dstItems[i].states = srcItem.states;
}
},
/**
* Returns whether the pipeline is flowing (contains item) currently.
* @method isFlowing