Use memoization in DygraphTransformation

pull/10616/head
Christopher Henn 2019-01-07 11:45:24 -08:00 committed by Chris Henn
parent d342fffbc9
commit 8fcd8ca594
1 changed files with 10 additions and 20 deletions

View File

@ -1,7 +1,10 @@
import {PureComponent} from 'react'
import {FluxTable} from 'src/types'
import memoizeOne from 'memoize-one'
import {ErrorHandling} from 'src/shared/decorators/errors'
import {FluxTable} from 'src/types'
import {
fluxTablesToDygraph,
FluxTablesToDygraphResult,
@ -13,27 +16,14 @@ interface Props {
}
@ErrorHandling
class DygraphTransformation extends PureComponent<
Props,
FluxTablesToDygraphResult
> {
public static getDerivedStateFromProps(props) {
return {...fluxTablesToDygraph(props.tables)}
}
constructor(props) {
super(props)
this.state = {
labels: [],
dygraphsData: [],
seriesDescriptions: [],
}
}
class DygraphTransformation extends PureComponent<Props> {
private fluxTablesToDygraph = memoizeOne(fluxTablesToDygraph)
public render() {
const {children} = this.props
return children(this.state)
const {tables, children} = this.props
const data = this.fluxTablesToDygraph(tables)
return children(data)
}
}