diff --git a/components/calendar.js b/components/calendar.js index 74b754bd7fb5283ae6dc01c9fd0de8ee7c032b3b..d9a0fd9a52c8784913126f5463ed53959974d01a 100644 --- a/components/calendar.js +++ b/components/calendar.js @@ -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) => { diff --git a/components/home.js b/components/home.js index 025a77b60c6fc560d7eda978b8ab8ed2f5b6f340..fffe6939b16daa9a6f8594bd0a2d32f19ecc2cea 100644 --- a/components/home.js +++ b/components/home.js @@ -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() {