Skip to content
Snippets Groups Projects
Commit 75a97089 authored by Julia Friesel's avatar Julia Friesel
Browse files

Remove listener when component unmounts

parent 80bf63ad
No related branches found
No related tags found
No related merge requests found
......@@ -11,7 +11,6 @@ import { saveBleeding } from './db'
import { formatDateForViewHeader } from './format'
import { bleeding as labels } from './labels'
import getCycleDay from './get-cycle-day'
import { bleedingDaysSortedByDate } from './db'
export default class Bleeding extends Component {
constructor(props) {
......
......@@ -9,10 +9,11 @@ export default class DatePickView extends Component {
super(props)
this.state = { bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) }
// so we rerender the calendar when there are new bleeding days
bleedingDaysSortedByDate.addListener(() => {
this.setState({ bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) })
})
bleedingDaysSortedByDate.addListener(setStateWithCalendarFormattedDays.bind(this))
}
componentWillUnmount() {
bleedingDaysSortedByDate.removeListener(setStateWithCalendarFormattedDays)
}
passDateToDayView(result) {
......@@ -43,4 +44,8 @@ function getBleedingDaysInCalFormat(bleedingDaysSortedByDate) {
acc[dateString] = { startingDay: true, endingDay: true, color: shadesOfRed[day.bleeding.value] }
return acc
}, {})
}
function setStateWithCalendarFormattedDays() {
this.setState({ bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) })
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment