Only remove component's listener, not all

This commit is contained in:
Julia Friesel
2018-06-14 17:29:21 +02:00
parent 1660db41e0
commit a46eb4421b
5 changed files with 1598 additions and 1583 deletions
+11 -7
View File
@@ -4,16 +4,24 @@ import { Calendar } from 'react-native-calendars'
import * as styles from './styles'
import { getOrCreateCycleDay, bleedingDaysSortedByDate } from './db'
export default class DatePickView extends Component {
export default class CalendarView extends Component {
constructor(props) {
super(props)
this.state = { bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) }
bleedingDaysSortedByDate.addListener(setStateWithCalendarFormattedDays.bind(this))
this.setStateWithCalendarFormattedDays = (function (CalendarComponent) {
return function() {
CalendarComponent.setState({
bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate)
})
}
})(this)
bleedingDaysSortedByDate.addListener(this.setStateWithCalendarFormattedDays)
}
componentWillUnmount() {
bleedingDaysSortedByDate.removeAllListeners()
bleedingDaysSortedByDate.removeListener(this.setStateWithCalendarFormattedDays)
}
passDateToDayView(result) {
@@ -41,8 +49,4 @@ function getBleedingDaysInCalFormat(bleedingDaysSortedByDate) {
acc[day.date] = { startingDay: true, endingDay: true, color: shadesOfRed[day.bleeding.value] }
return acc
}, {})
}
function setStateWithCalendarFormattedDays() {
this.setState({ bleedingDaysInCalFormat: getBleedingDaysInCalFormat(bleedingDaysSortedByDate) })
}