remove cancelAnimationFrame complexity and rely on MarkedExecution class
parent
09c22c37ff
commit
652e06a7b1
|
@ -34,10 +34,16 @@ interface IState {
|
|||
@replaceableComponent("views.voice_messages.LiveRecordingClock")
|
||||
export default class LiveRecordingClock extends React.PureComponent<IProps, IState> {
|
||||
private seconds = 0;
|
||||
private rafId: number;
|
||||
private scheduledUpdate = new MarkedExecution(
|
||||
() => this.updateClock(),
|
||||
() => requestAnimationFrame(() => this.scheduledUpdate.trigger()),
|
||||
)
|
||||
|
||||
state = {
|
||||
seconds: 0,
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
seconds: 0,
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -47,24 +53,10 @@ export default class LiveRecordingClock extends React.PureComponent<IProps, ISta
|
|||
});
|
||||
}
|
||||
|
||||
private scheduledUpdate = new MarkedExecution(
|
||||
() => this.updateClock(),
|
||||
() => this.onLiveDataUpdate(),
|
||||
)
|
||||
|
||||
private onLiveDataUpdate() {
|
||||
if (this.rafId) {
|
||||
cancelAnimationFrame(this.rafId);
|
||||
}
|
||||
|
||||
this.rafId = requestAnimationFrame(() => this.scheduledUpdate.trigger())
|
||||
}
|
||||
|
||||
private updateClock() {
|
||||
this.setState({
|
||||
seconds: this.seconds,
|
||||
})
|
||||
this.rafId = null;
|
||||
}
|
||||
|
||||
public render() {
|
||||
|
|
|
@ -38,10 +38,16 @@ export default class LiveRecordingWaveform extends React.PureComponent<IProps, I
|
|||
};
|
||||
|
||||
private waveform: number[] = [];
|
||||
private rafId: number;
|
||||
private scheduledUpdate = new MarkedExecution(
|
||||
() => this.updateWaveform(),
|
||||
() => requestAnimationFrame(() => this.scheduledUpdate.trigger()),
|
||||
)
|
||||
|
||||
state = {
|
||||
waveform: [],
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
waveform: [],
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -51,24 +57,10 @@ export default class LiveRecordingWaveform extends React.PureComponent<IProps, I
|
|||
});
|
||||
}
|
||||
|
||||
private scheduledUpdate = new MarkedExecution(
|
||||
() => this.updateWaveform(),
|
||||
() => this.onLiveDataUpdate(),
|
||||
)
|
||||
|
||||
private onLiveDataUpdate() {
|
||||
if (this.rafId) {
|
||||
cancelAnimationFrame(this.rafId);
|
||||
}
|
||||
|
||||
this.rafId = requestAnimationFrame(() => this.scheduledUpdate.trigger())
|
||||
}
|
||||
|
||||
private updateWaveform() {
|
||||
this.setState({
|
||||
waveform: this.waveform,
|
||||
})
|
||||
this.rafId = null;
|
||||
}
|
||||
|
||||
public render() {
|
||||
|
|
|
@ -33,13 +33,6 @@ export class MarkedExecution {
|
|||
constructor(private fn: () => void, private onMarkCallback?: () => void) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the _marked property
|
||||
*/
|
||||
public get marked() {
|
||||
return this._marked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the mark without calling the function.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue