mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-03 09:32:38 +08:00
Remove callbacks after flowout an item to avoid duplicated callback calls
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user