mirror of https://github.com/vector-im/riot-web
remove cancelAnimationFrame complexity and rely on MarkedExecution class
parent
09c22c37ff
commit
652e06a7b1
|
@ -34,11 +34,17 @@ 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) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
seconds: 0,
|
seconds: 0,
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.recorder.liveData.onUpdate((update: IRecordingUpdate) => {
|
this.props.recorder.liveData.onUpdate((update: IRecordingUpdate) => {
|
||||||
|
@ -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,11 +38,17 @@ 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) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
waveform: [],
|
waveform: [],
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.props.recorder.liveData.onUpdate((update: IRecordingUpdate) => {
|
this.props.recorder.liveData.onUpdate((update: IRecordingUpdate) => {
|
||||||
|
@ -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