Attach and remove listeners from same db collection
This commit is contained in:
@@ -9,11 +9,11 @@ import styles from '../styles/index'
|
||||
|
||||
export default class CalendarView extends Component {
|
||||
constructor(props) {
|
||||
const bleedingDaysSortedByDate = getBleedingDaysSortedByDate()
|
||||
super(props)
|
||||
this.bleedingDays = getBleedingDaysSortedByDate()
|
||||
const predictedMenses = cycleModule().getPredictedMenses()
|
||||
this.state = {
|
||||
bleedingDaysInCalFormat: toCalFormat(bleedingDaysSortedByDate),
|
||||
bleedingDaysInCalFormat: toCalFormat(this.bleedingDays),
|
||||
predictedBleedingDaysInCalFormat: predictionToCalFormat(predictedMenses),
|
||||
todayInCalFormat: todayToCalFormat()
|
||||
}
|
||||
@@ -22,18 +22,18 @@ export default class CalendarView extends Component {
|
||||
return function() {
|
||||
const predictedMenses = cycleModule().getPredictedMenses()
|
||||
CalendarComponent.setState({
|
||||
bleedingDaysInCalFormat: toCalFormat(bleedingDaysSortedByDate),
|
||||
bleedingDaysInCalFormat: toCalFormat(this.bleedingDays),
|
||||
predictedBleedingDaysInCalFormat: predictionToCalFormat(predictedMenses),
|
||||
todayInCalFormat: todayToCalFormat()
|
||||
})
|
||||
}
|
||||
})(this)
|
||||
|
||||
bleedingDaysSortedByDate.addListener(this.setStateWithCalFormattedDays)
|
||||
this.bleedingDays.addListener(this.setStateWithCalFormattedDays)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
getBleedingDaysSortedByDate().removeListener(this.setStateWithCalFormattedDays)
|
||||
this.bleedingDays.removeListener(this.setStateWithCalFormattedDays)
|
||||
}
|
||||
|
||||
passDateToDayView = (result) => {
|
||||
|
||||
+12
-13
@@ -14,30 +14,29 @@ import {bleedingPrediction as labels} from './labels'
|
||||
export default class Home extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
const getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||
this.getCycleDayNumber = cycleModule().getCycleDayNumber
|
||||
this.todayDateString = LocalDate.now().toString()
|
||||
const cycleDayNumber = getCycleDayNumber(this.todayDateString)
|
||||
const cycleDayNumber = this.getCycleDayNumber(this.todayDateString)
|
||||
|
||||
this.state = {
|
||||
welcomeText: determineWelcomeText(cycleDayNumber),
|
||||
predictionText: determinePredictionText()
|
||||
}
|
||||
|
||||
this.setStateWithCurrentText = (function (HomeComponent) {
|
||||
return function () {
|
||||
const cycleDayNumber = getCycleDayNumber(HomeComponent.todayDateString)
|
||||
HomeComponent.setState({
|
||||
welcomeText: determineWelcomeText(cycleDayNumber),
|
||||
predictionText: determinePredictionText()
|
||||
})
|
||||
}
|
||||
})(this)
|
||||
this.bleedingDays = getBleedingDaysSortedByDate()
|
||||
this.bleedingDays.addListener(this.setStateWithCurrentText)
|
||||
}
|
||||
|
||||
getBleedingDaysSortedByDate().addListener(this.setStateWithCurrentText)
|
||||
setStateWithCurrentText = () => {
|
||||
const cycleDayNumber = this.getCycleDayNumber(this.todayDateString)
|
||||
this.setState({
|
||||
welcomeText: determineWelcomeText(cycleDayNumber),
|
||||
predictionText: determinePredictionText()
|
||||
})
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
getBleedingDaysSortedByDate().removeListener(this.setStateWithCurrentText)
|
||||
this.bleedingDays.removeListener(this.setStateWithCurrentText)
|
||||
}
|
||||
|
||||
passTodayToDayView() {
|
||||
|
||||
Reference in New Issue
Block a user