Skip to content

Commit 848b5ae

Browse files
committed
add two helper methods replaceChunk and replaceParent
they take an old item and a new item, remove the old item and add the new one
1 parent 5fa6caa commit 848b5ae

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

lib/Chunk.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ class Chunk {
169169
module.rewriteChunkInReasons(this, [otherChunk]);
170170
}
171171

172+
replaceChunk(oldChunk, newChunk) {
173+
const idx = this.chunks.indexOf(oldChunk);
174+
if(idx >= 0) {
175+
this.chunks.splice(idx, 1);
176+
}
177+
if(this !== newChunk && newChunk.addParent(this)) {
178+
this.addChunk(newChunk);
179+
}
180+
}
181+
182+
replaceParent(oldParent, newParent) {
183+
const idx = this.parents.indexOf(oldParent);
184+
if(idx >= 0) {
185+
this.parents.splice(idx, 1);
186+
}
187+
if(this !== newParent && newParent.addChunk(this)) {
188+
this.addParent(newParent);
189+
}
190+
}
191+
172192
integrate(other, reason) {
173193
if(!this.canBeIntegrated(other)) {
174194
return false;

0 commit comments

Comments
 (0)