Skip to content

Commit da9c842

Browse files
Ensure original unregisterSubscriptions get called
1 parent 45eb869 commit da9c842

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/thread.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,9 @@ export class Thread extends WithSubscriptions {
448448
};
449449

450450
public unregisterSubscriptions = () => {
451-
super.unregisterSubscriptions();
451+
const symbol = super.unregisterSubscriptions();
452452
this.state.partialNext({ isStateStale: true });
453+
return symbol;
453454
};
454455

455456
public deleteReplyLocally = ({ message }: { message: MessageResponse }) => {

src/thread_manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export class ThreadManager extends WithSubscriptions {
219219
this.state
220220
.getLatestValue()
221221
.threads.forEach((thread) => thread.unregisterSubscriptions());
222-
super.unregisterSubscriptions();
222+
return super.unregisterSubscriptions();
223223
};
224224

225225
public reload = async ({ force = false } = {}) => {

src/utils/WithSubscriptions.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import type { Unsubscribe } from '../store';
66
*/
77
export abstract class WithSubscriptions {
88
private unsubscribeFunctions: Set<Unsubscribe> = new Set();
9+
/**
10+
* Workaround for the missing TS keyword - ensures that inheritants
11+
* overriding `unregisterSubscriptions` call the base method and return
12+
* its unique symbol value.
13+
*/
14+
private static symbol = Symbol(WithSubscriptions.name);
915

1016
public abstract registerSubscriptions(): void;
1117

@@ -25,18 +31,21 @@ export abstract class WithSubscriptions {
2531
* If you re-declare `unregisterSubscriptions` method within your class
2632
* make sure to run the original too.
2733
*
28-
* @example
34+
* @example
2935
* ```ts
30-
* class T {
36+
* class T extends WithSubscriptions {
37+
* ...
3138
* public unregisterSubscriptions = () => {
32-
* super.unregisterSubscriptions();
3339
* this.customThing();
40+
* return super.unregisterSubscriptions();
3441
* }
3542
* }
3643
* ```
3744
*/
38-
public unregisterSubscriptions() {
45+
public unregisterSubscriptions(): typeof WithSubscriptions.symbol {
3946
this.unsubscribeFunctions.forEach((unsubscribe) => unsubscribe());
4047
this.unsubscribeFunctions.clear();
48+
49+
return WithSubscriptions.symbol;
4150
}
4251
}

0 commit comments

Comments
 (0)