Only use db functions when components are actually mounted
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,13 @@ import { getOrCreateCycleDay } from '../../db'
|
||||
import cycleModule from '../../lib/cycle'
|
||||
import DotAndLine from './dot-and-line'
|
||||
|
||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||
const label = styles.column.label
|
||||
|
||||
export default class DayColumn extends Component {
|
||||
constructor() {
|
||||
super()
|
||||
this.getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||
}
|
||||
passDateToDayView(dateString) {
|
||||
const cycleDay = getOrCreateCycleDay(dateString)
|
||||
this.props.navigate('CycleDay', { cycleDay })
|
||||
@@ -68,7 +71,7 @@ export default class DayColumn extends Component {
|
||||
)
|
||||
}
|
||||
|
||||
const cycleDayNumber = getCycleDayNumber(dateString)
|
||||
const cycleDayNumber = this.getCycleDayNumber(dateString)
|
||||
const shortDate = dateString.split('-').slice(1).join('-')
|
||||
const cycleDayLabel = (
|
||||
<Text style = {label.number}>
|
||||
|
||||
Reference in New Issue
Block a user