Move functions out of render and into getters

pull/3159/head
Andrew Watkins 2018-04-09 20:12:18 -07:00
parent 37b50cb956
commit adbc4dbce0
1 changed files with 17 additions and 14 deletions

View File

@ -45,31 +45,23 @@ class Annotations extends Component {
staticLegendHeight,
} = this.props
const annotations = visibleAnnotations(
dygraph,
this.props.annotations
).filter(a => a.id !== TEMP_ANNOTATION.id)
const tempAnnotation = this.props.annotations.find(
a => a.id === TEMP_ANNOTATION.id
)
return (
<div className="annotations-container">
{mode === ADDING &&
tempAnnotation && (
this.tempAnnotation && (
<NewAnnotation
dygraph={dygraph}
tempAnnotation={tempAnnotation}
isTempHovering={isTempHovering}
tempAnnotation={this.tempAnnotation}
staticLegendHeight={staticLegendHeight}
onUpdateAnnotation={handleUpdateAnnotation}
onDismissAddingAnnotation={handleDismissAddingAnnotation}
onAddingAnnotationSuccess={handleAddingAnnotationSuccess}
onUpdateAnnotation={handleUpdateAnnotation}
isTempHovering={isTempHovering}
onMouseEnterTempAnnotation={handleMouseEnterTempAnnotation}
onMouseLeaveTempAnnotation={handleMouseLeaveTempAnnotation}
staticLegendHeight={staticLegendHeight}
/>
)}
{annotations.map(a => (
{this.annotations.map(a => (
<Annotation
key={a.id}
mode={mode}
@ -82,6 +74,17 @@ class Annotations extends Component {
</div>
)
}
get annotations() {
return visibleAnnotations(
this.props.dygraph,
this.props.annotations
).filter(a => a.id !== TEMP_ANNOTATION.id)
}
get tempAnnotation() {
return this.props.annotations.find(a => a.id === TEMP_ANNOTATION.id)
}
}
const {arrayOf, bool, func, number, shape, string} = PropTypes