Skip to content
Snippets Groups Projects
Commit b4972418 authored by Jack Reed's avatar Jack Reed
Browse files

refactor ruler plugin to remove memory leaks, only set state when mounted

parent 0063a651
No related branches found
No related tags found
No related merge requests found
......@@ -34,27 +34,39 @@
class MiradorRuler extends React.Component {
constructor(props) {
super(props);
this._isMounted = false;
this.state = {
zooming: false,
}
this.zoomToColor = this.zoomToColor.bind(this);
}
componentDidMount() {
this._isMounted = true;
const that = this;
this.props.pluginParent().viewer.addHandler('zoom', (e) => {
this.setState({
if (that._isMounted) {
that.setState({
zooming: true
})
}
})
const that = this;
// Super hacky don't do this for real
function resetStyle() {
if (that._isMounted) {
that.setState({
zooming: false
})
}
setTimeout(resetStyle, 750)
}
resetStyle();
}
componentWillUnmount() {
this._isMounted = false;
if (this.props.pluginParent()) {
this.props.pluginParent().viewer.removeHandler('zoom');
}
}
zoomToColor(zooming) {
if (zooming) {
return 'red'
......@@ -62,13 +74,13 @@
return 'black'
}
render() {
return React.createElement('div', {className: 'mirador-ruler', style: {position: 'absolute', color: this.zoomToColor(this.state.zooming)}}, 'I am a ruler')
return React.createElement('div', {className: 'mirador-ruler', style: { position: 'absolute', bottom: 0, color: this.zoomToColor(this.state.zooming)}}, 'I am a ruler')
}
}
const miradorRuler = {
name: 'miradorRuler',
component: MiradorRuler,
parent: 'WindowViewer',
parent: 'OpenSeadragonViewer',
mapStateToProps: ({ manifests }, props) => {
return {
manifests // return the part of the state I need here.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment