Merge pull request #1760 from pandamicro/v1.5

Fix circle reference check issue
This commit is contained in:
Wang Nan
2017-06-26 18:15:41 +08:00
committed by GitHub
2 changed files with 11 additions and 10 deletions
+1 -7
View File
@@ -261,10 +261,6 @@ proto.load = function(resources, progressCallback, completeCallback) {
};
proto.flowInDeps = function (owner, urlList, callback) {
if (owner && !owner.deps) {
owner.deps = [];
}
_sharedList.length = 0;
for (var i = 0; i < urlList.length; ++i) {
var res = getResWithUrl(urlList[i]);
@@ -273,8 +269,6 @@ proto.flowInDeps = function (owner, urlList, callback) {
var item = this.getItem(res.url);
if (item) {
_sharedList.push(item);
// Collect deps to avoid circle reference
owner && owner.deps.push(item);
}
else {
_sharedList.push(res);
@@ -289,7 +283,7 @@ proto.flowInDeps = function (owner, urlList, callback) {
callback(errors, items);
// Clear deps because it's already done
// Each item will only flowInDeps once, so it's still safe here
owner && (owner.deps.length = 0);
owner && owner.deps && (owner.deps.length = 0);
items.destroy();
});
if (owner) {
+10 -3
View File
@@ -413,7 +413,7 @@ LoadingItems.initQueueDeps = function (queue) {
}
};
LoadingItems.registerDep = function (owner, depId) {
LoadingItems.registerQueueDep = function (owner, depId) {
var queueId = owner.queueId || owner;
if (!queueId) {
return false;
@@ -463,6 +463,9 @@ proto.append = function (urlList, owner) {
if (!this.active) {
return [];
}
if (owner && !owner.deps) {
owner.deps = [];
}
this._appending = true;
var accepted = [], i, url, item;
@@ -472,6 +475,8 @@ proto.append = function (urlList, owner) {
// Already queued in another items queue, url is actually the item
if (url.queueId && !this.map[url.id]) {
this.map[url.id] = url;
// Register item deps for circle reference check
owner && owner.deps.push(url);
// Queued and completed or Owner circle referenced by dependency
if (url.complete || checkCircleReference(owner, url)) {
this.totalCount++;
@@ -485,7 +490,7 @@ proto.append = function (urlList, owner) {
var queue = _queues[url.queueId];
if (queue) {
this.totalCount++;
LoadingItems.registerDep(owner || this._id, url.id);
LoadingItems.registerQueueDep(owner || this._id, url.id);
// console.log('+++++ Waited ' + url.id);
queue.addListener(url.id, function (item) {
// console.log('----- Completed by waiting ' + item.id + ', rest: ' + (self.totalCount - self.completedCount-1));
@@ -503,7 +508,9 @@ proto.append = function (urlList, owner) {
if (!this.map[key]) {
this.map[key] = item;
this.totalCount++;
LoadingItems.registerDep(owner || this._id, key);
// Register item deps for circle reference check
owner && owner.deps.push(item);
LoadingItems.registerQueueDep(owner || this._id, key);
accepted.push(item);
// console.log('+++++ Appended ' + item.id);
}