Improve typing around event emitter handlers (#7816)
This commit is contained in:
parent
213b32bf14
commit
7fa01ffb06
79 changed files with 548 additions and 471 deletions
|
@ -16,8 +16,8 @@ limitations under the License.
|
|||
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { Relations } from 'matrix-js-sdk/src/models/relations';
|
||||
import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/models/event";
|
||||
import { Relations, RelationsEvent } from 'matrix-js-sdk/src/models/relations';
|
||||
import { MatrixClient } from 'matrix-js-sdk/src/matrix';
|
||||
import {
|
||||
M_POLL_END,
|
||||
|
@ -228,37 +228,37 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
|
|||
};
|
||||
|
||||
this.addListeners(this.state.voteRelations, this.state.endRelations);
|
||||
this.props.mxEvent.on("Event.relationsCreated", this.onRelationsCreated);
|
||||
this.props.mxEvent.on(MatrixEventEvent.RelationsCreated, this.onRelationsCreated);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.mxEvent.off("Event.relationsCreated", this.onRelationsCreated);
|
||||
this.props.mxEvent.off(MatrixEventEvent.RelationsCreated, this.onRelationsCreated);
|
||||
this.removeListeners(this.state.voteRelations, this.state.endRelations);
|
||||
}
|
||||
|
||||
private addListeners(voteRelations?: RelatedRelations, endRelations?: RelatedRelations) {
|
||||
if (voteRelations) {
|
||||
voteRelations.on("Relations.add", this.onRelationsChange);
|
||||
voteRelations.on("Relations.remove", this.onRelationsChange);
|
||||
voteRelations.on("Relations.redaction", this.onRelationsChange);
|
||||
voteRelations.on(RelationsEvent.Add, this.onRelationsChange);
|
||||
voteRelations.on(RelationsEvent.Remove, this.onRelationsChange);
|
||||
voteRelations.on(RelationsEvent.Redaction, this.onRelationsChange);
|
||||
}
|
||||
if (endRelations) {
|
||||
endRelations.on("Relations.add", this.onRelationsChange);
|
||||
endRelations.on("Relations.remove", this.onRelationsChange);
|
||||
endRelations.on("Relations.redaction", this.onRelationsChange);
|
||||
endRelations.on(RelationsEvent.Add, this.onRelationsChange);
|
||||
endRelations.on(RelationsEvent.Remove, this.onRelationsChange);
|
||||
endRelations.on(RelationsEvent.Redaction, this.onRelationsChange);
|
||||
}
|
||||
}
|
||||
|
||||
private removeListeners(voteRelations?: RelatedRelations, endRelations?: RelatedRelations) {
|
||||
if (voteRelations) {
|
||||
voteRelations.off("Relations.add", this.onRelationsChange);
|
||||
voteRelations.off("Relations.remove", this.onRelationsChange);
|
||||
voteRelations.off("Relations.redaction", this.onRelationsChange);
|
||||
voteRelations.off(RelationsEvent.Add, this.onRelationsChange);
|
||||
voteRelations.off(RelationsEvent.Remove, this.onRelationsChange);
|
||||
voteRelations.off(RelationsEvent.Redaction, this.onRelationsChange);
|
||||
}
|
||||
if (endRelations) {
|
||||
endRelations.off("Relations.add", this.onRelationsChange);
|
||||
endRelations.off("Relations.remove", this.onRelationsChange);
|
||||
endRelations.off("Relations.redaction", this.onRelationsChange);
|
||||
endRelations.off(RelationsEvent.Add, this.onRelationsChange);
|
||||
endRelations.off(RelationsEvent.Remove, this.onRelationsChange);
|
||||
endRelations.off(RelationsEvent.Redaction, this.onRelationsChange);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,8 +282,7 @@ export default class MPollBody extends React.Component<IBodyProps, IState> {
|
|||
}
|
||||
|
||||
if (this.voteRelationsReceived && this.endRelationsReceived) {
|
||||
this.props.mxEvent.removeListener(
|
||||
"Event.relationsCreated", this.onRelationsCreated);
|
||||
this.props.mxEvent.removeListener(MatrixEventEvent.RelationsCreated, this.onRelationsCreated);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue