Only use db functions when components are actually mounted

This commit is contained in:
Julia Friesel
2018-09-11 18:06:19 +02:00
parent 04e43b823d
commit 3e3cef8769
6 changed files with 25 additions and 20 deletions
+4 -3
View File
@@ -5,7 +5,7 @@ import { LocalDate } from 'js-joda'
import { makeYAxisLabels, normalizeToScale, makeHorizontalGrid } from './y-axis'
import nfpLines from './nfp-lines'
import DayColumn from './day-column'
import { getCycleDay, cycleDaysSortedByDate, getAmountOfCycleDays } from '../../db'
import { getCycleDay, getCycleDaysSortedByDate, getAmountOfCycleDays } from '../../db'
import styles from './styles'
import { scaleObservable } from '../../local-storage'
import config from '../../config'
@@ -25,6 +25,7 @@ export default class CycleChart extends Component {
/>
)
}
this.cycleDaysSortedByDate = getCycleDaysSortedByDate()
}
onLayout = ({ nativeEvent }) => {
@@ -35,12 +36,12 @@ export default class CycleChart extends Component {
this.setState({ columns: this.makeColumnInfo(nfpLines(height)) })
}
cycleDaysSortedByDate.addListener(this.reCalculateChartInfo)
this.cycleDaysSortedByDate.addListener(this.reCalculateChartInfo)
this.removeObvListener = scaleObservable(this.reCalculateChartInfo, false)
}
componentWillUnmount() {
cycleDaysSortedByDate.removeListener(this.reCalculateChartInfo)
this.cycleDaysSortedByDate.removeListener(this.reCalculateChartInfo)
this.removeObvListener()
}