Skip to content

Commit be0ac75

Browse files
committed
feat: add loaderQueue.removeContent
1 parent 491c8d6 commit be0ac75

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/loader/LoadQueue.js

+22
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,28 @@ var LoadQueue = Class.create(/** @lends LoadQueue.prototype */{
130130
var item = this.get(id);
131131
return item && item.content;
132132
},
133+
/**
134+
* @language=en
135+
* remove resource object content by id or src
136+
* @param {String} specified id or src
137+
*/
138+
/**
139+
* @language=zh
140+
* 根据id或src地址删除资源内容。
141+
* @param {String} id 指定资源的id或src。
142+
*/
143+
removeContent: function(id){
144+
if(id){
145+
var source = this._source;
146+
for(var i = 0; i < source.length; i++){
147+
var item = source[i];
148+
if(item.id === id || item.src === id){
149+
source.splice(i, 1);
150+
return;
151+
}
152+
}
153+
}
154+
},
133155

134156
/**
135157
* @language=en

test/loader.js

+2
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ describe('loader', function(){
9797
queue.getContent('btn').should.instanceOf(Image);
9898
queue.getContent('btn').width.should.equal(256);
9999
queue.getContent('btn').height.should.equal(128);
100+
queue.removeContent('btn');
101+
(queue.getContent('btn') == null).should.be.true();
100102
done();
101103
}
102104
catch(e){

0 commit comments

Comments
 (0)