diff --git a/cocos2d/core/load-pipeline/downloader.js b/cocos2d/core/load-pipeline/downloader.js index 4275c2945c..2fdd21f234 100644 --- a/cocos2d/core/load-pipeline/downloader.js +++ b/cocos2d/core/load-pipeline/downloader.js @@ -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); }); } }); diff --git a/cocos2d/core/load-pipeline/pipeline.js b/cocos2d/core/load-pipeline/pipeline.js index 78c9fc5a2c..a129407768 100644 --- a/cocos2d/core/load-pipeline/pipeline.js +++ b/cocos2d/core/load-pipeline/pipeline.js @@ -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