You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-04 05:02:41 +03:00
Use WeakMap in ReEmitter to help enable garbage collection (#3344)
This commit is contained in:
committed by
GitHub
parent
83cb52c89c
commit
49696cecbd
@@ -25,7 +25,7 @@ export class ReEmitter {
|
|||||||
public constructor(private readonly target: EventEmitter) {}
|
public constructor(private readonly target: EventEmitter) {}
|
||||||
|
|
||||||
// Map from emitter to event name to re-emitter
|
// Map from emitter to event name to re-emitter
|
||||||
private reEmitters = new Map<EventEmitter, Map<string, (...args: any[]) => void>>();
|
private reEmitters = new WeakMap<EventEmitter, Map<string, (...args: any[]) => void>>();
|
||||||
|
|
||||||
public reEmit(source: EventEmitter, eventNames: string[]): void {
|
public reEmit(source: EventEmitter, eventNames: string[]): void {
|
||||||
let reEmittersByEvent = this.reEmitters.get(source);
|
let reEmittersByEvent = this.reEmitters.get(source);
|
||||||
@@ -35,6 +35,8 @@ export class ReEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const eventName of eventNames) {
|
for (const eventName of eventNames) {
|
||||||
|
if (reEmittersByEvent.has(eventName)) continue;
|
||||||
|
|
||||||
// We include the source as the last argument for event handlers which may need it,
|
// We include the source as the last argument for event handlers which may need it,
|
||||||
// such as read receipt listeners on the client class which won't have the context
|
// such as read receipt listeners on the client class which won't have the context
|
||||||
// of the room.
|
// of the room.
|
||||||
|
|||||||
Reference in New Issue
Block a user