Remove callbacks after flowout an item to avoid duplicated callback calls

This commit is contained in:
pandamicro
2016-02-29 14:47:58 +08:00
parent 572a5cd8f2
commit 535ed9406d
4 changed files with 14 additions and 5 deletions
+2 -1
View File
@@ -308,7 +308,8 @@ var game = /** @lends cc.game# */{
// @ Persist root node section
/**
* Add a persistent root node to the game, the persistent node won't be destroyed during scene transition
* Add a persistent root node to the game, the persistent node won't be destroyed during scene transition.
* The target node must be placed in the root level of hierarchy, otherwise this API won't have any effect.
* @method addPersistRootNode
* @param {Node} node - The node to be made persistent
*/
+2
View File
@@ -33,6 +33,7 @@ var loader = new Loader();
/**
* Loader for resource loading process. It's a singleton object.
* @class loader
* @extends Pipeline
* @static
*/
cc.loader = new Pipeline([
@@ -146,6 +147,7 @@ JS.mixin(cc.loader, {
function loadedCheck (item) {
checker[item.src] = item;
self._items.remove(item.src, loadedCheck);
if (item.error) {
error = error || [];
error.push(item.src);
+2 -1
View File
@@ -39,6 +39,7 @@ var JS = require('../platform/js');
* Item can hold other custom properties
*
* @class LoadingItems
* @extends CallbacksInvoker
*/
var LoadingItems = function () {
CallbacksInvoker.call(this);
@@ -126,7 +127,7 @@ JS.mixin(LoadingItems.prototype, CallbacksInvoker.prototype, {
* Remove an item, can only remove completed item, ongoing item can not be removed
* @param {String} url
*/
remove: function (url) {
removeItem: function (url) {
if (this.completed[url]) {
delete this.completed[url];
delete this.map[url];
+8 -3
View File
@@ -318,8 +318,10 @@ JS.mixin(Pipeline.prototype, {
var checker = {};
var count = 0;
var items = this._items;
function loadedCheck (item) {
checker[item.src] = item;
items.remove(item.src, loadedCheck);
for (var url in checker) {
// Not done yet
@@ -335,9 +337,9 @@ JS.mixin(Pipeline.prototype, {
var url = urlList[i].src || urlList[i];
if (typeof url !== 'string')
continue;
var item = this._items.map[url];
var item = items.map[url];
if ( !item ) {
this._items.add(url, loadedCheck);
items.add(url, loadedCheck);
checker[url] = null;
count++;
}
@@ -389,6 +391,9 @@ JS.mixin(Pipeline.prototype, {
this.complete();
items.invoke(url, item);
// remove all callbacks added for url
items.removeAll(url);
},
/**
@@ -443,7 +448,7 @@ JS.mixin(Pipeline.prototype, {
item.error = new Error('Canceled manually');
this.flowOut(item);
}
this._items.remove(url);
this._items.removeItem(url);
}
else {
return false;