Skip to content

Commit a9110d7

Browse files
committed
fixed clip detach bug
1 parent 11f61bf commit a9110d7

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@diffusionstudio/core",
33
"private": false,
4-
"version": "1.4.2",
4+
"version": "1.4.3",
55
"type": "module",
66
"description": "Build bleeding edge video processing applications",
77
"files": [

src/clips/clip/clip.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,40 @@ describe('The Clip Object', () => {
8484
expect(clip.track?.id).toBe(track.id);
8585
});
8686

87+
it('should remove event listeners on detach', async () => {
88+
const clip0 = new Clip({ start: 0, stop: 20 });
89+
const clip1 = new Clip({ stop: 60, start: 30 });
90+
91+
const composition = new Composition();
92+
const track0 = composition.createTrack('base');
93+
const track1 = composition.createTrack('base');
94+
95+
await track0.add(clip0);
96+
await track0.add(clip1);
97+
98+
expect(track0.clips.length).toBe(2);
99+
expect(track0.clips[0].start.frames).toBe(0);
100+
expect(track0.clips[0].stop.frames).toBe(20);
101+
102+
expect(track0.clips[1].start.frames).toBe(30);
103+
expect(track0.clips[1].stop.frames).toBe(60);
104+
105+
clip1.detach();
106+
107+
expect(track0.clips.length).toBe(1);
108+
109+
await track1.add(clip1);
110+
111+
expect(track1.clips.length).toBe(1);
112+
expect(track1.clips[0].start.frames).toBe(30);
113+
expect(track1.clips[0].stop.frames).toBe(60);
114+
115+
clip1.start = 10;
116+
117+
expect(track1.clips[0].start.frames).toBe(10);
118+
expect(track1.clips[0].stop.frames).toBe(60);
119+
});
120+
87121
it('should be removable from the track', async () => {
88122
const clip1 = new Clip({ stop: 900, start: 570 });
89123

src/composition/composition.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ export class Composition extends EventEmitterMixin<CompositionEvents, typeof Ser
490490
if (index != undefined && index >= 0) {
491491
this.tracks.splice(index, 1);
492492
this.trigger('detach', undefined);
493+
track.off('*');
493494
return track;
494495
}
495496
}

src/mixins/event.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,14 @@ export function EventEmitterMixin<Events = {}, T extends Constructor = Construct
3636
return id;
3737
}
3838

39-
public off(id?: string, ...ids: string[]) {
39+
public off(id?: string | '*', ...ids: string[]) {
4040
if (!id) return;
4141

42+
if (id === '*') {
43+
this._handlers = {};
44+
return;
45+
}
46+
4247
for (const obj of Object.values(this._handlers)) {
4348
if (id in obj) {
4449
delete obj[id];

src/tracks/track/track.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export class Track<Clp extends Clip> extends EventEmitterMixin<Events, typeof Se
233233
this.clips.splice(index, 1);
234234
this.strategy.update(clip, this);
235235
this.trigger('detach', undefined);
236+
clip.off('*');
236237

237238
return clip;
238239
}

0 commit comments

Comments
 (0)