mirror of https://github.com/vector-im/riot-web
remove cancelAnimationFrame complexity and rely on MarkedExecution class
parent
09c22c37ff
commit
652e06a7b1
|
@ -34,10 +34,16 @@ interface IState {
|
||||||
@replaceableComponent("views.voice_messages.LiveRecordingClock")
|
@replaceableComponent("views.voice_messages.LiveRecordingClock")
|
||||||
export default class LiveRecordingClock extends React.PureComponent<IProps, IState> {
|
export default class LiveRecordingClock extends React.PureComponent<IProps, IState> {
|
||||||
private seconds = 0;
|
private seconds = 0;
|
||||||
private rafId: number;
|
private scheduledUpdate = new MarkedExecution(
|
||||||
|
() => this.updateClock(),
|
||||||
|
() => requestAnimationFrame(() => this.scheduledUpdate.trigger()),
|
||||||
|
)
|
||||||
|
|
||||||
state = {
|
constructor(props) {
|
||||||
seconds: 0,
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
seconds: 0,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
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() {
|
private updateClock() {
|
||||||
this.setState({
|
this.setState({
|
||||||
seconds: this.seconds,
|
seconds: this.seconds,
|
||||||
})
|
})
|
||||||
this.rafId = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
|
|
|
@ -38,10 +38,16 @@ export default class LiveRecordingWaveform extends React.PureComponent<IProps, I
|
||||||
};
|
};
|
||||||
|
|
||||||
private waveform: number[] = [];
|
private waveform: number[] = [];
|
||||||
private rafId: number;
|
private scheduledUpdate = new MarkedExecution(
|
||||||
|
() => this.updateWaveform(),
|
||||||
|
() => requestAnimationFrame(() => this.scheduledUpdate.trigger()),
|
||||||
|
)
|
||||||
|
|
||||||
state = {
|
constructor(props) {
|
||||||
waveform: [],
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
waveform: [],
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
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() {
|
private updateWaveform() {
|
||||||
this.setState({
|
this.setState({
|
||||||
waveform: this.waveform,
|
waveform: this.waveform,
|
||||||
})
|
})
|
||||||
this.rafId = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
|
|
|
@ -33,13 +33,6 @@ export class MarkedExecution {
|
||||||
constructor(private fn: () => void, private onMarkCallback?: () => void) {
|
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.
|
* Resets the mark without calling the function.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue