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

Use nothing-changed helper in home to prevent unnecessary render

parent dca286a1
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,7 @@ import { getOrCreateCycleDay, getCycleDaysSortedByDate } from '../db' ...@@ -11,6 +11,7 @@ import { getOrCreateCycleDay, getCycleDaysSortedByDate } from '../db'
import { getFertilityStatusForDay } from '../lib/sympto-adapter' import { getFertilityStatusForDay } from '../lib/sympto-adapter'
import styles from '../styles' import styles from '../styles'
import AppText, { AppTextLight } from './app-text' import AppText, { AppTextLight } from './app-text'
import nothingChanged from '../helpers/db-unchanged'
export default class Home extends Component { export default class Home extends Component {
constructor(props) { constructor(props) {
...@@ -32,7 +33,8 @@ export default class Home extends Component { ...@@ -32,7 +33,8 @@ export default class Home extends Component {
this.cycleDays.addListener(this.updateState) this.cycleDays.addListener(this.updateState)
} }
updateState = () => { updateState = (_, changes) => {
if (nothingChanged(changes)) return
const prediction = this.getBleedingPrediction() const prediction = this.getBleedingPrediction()
const fertilityStatus = getFertilityStatusForDay(this.todayDateString) const fertilityStatus = getFertilityStatusForDay(this.todayDateString)
this.setState({ this.setState({
......
export default function (dbChanges) {
return Object.values(dbChanges).every(changeArray => changeArray.length === 0)
}
\ No newline at end of file
...@@ -5,6 +5,7 @@ import Moment from 'moment' ...@@ -5,6 +5,7 @@ import Moment from 'moment'
import { settings as labels } from '../components/labels' import { settings as labels } from '../components/labels'
import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db' import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db'
import cycleModule from './cycle' import cycleModule from './cycle'
import nothingChanged from '../helpers/db-unchanged'
export default function setupNotifications(navigate) { export default function setupNotifications(navigate) {
Notification.configure({ Notification.configure({
...@@ -80,7 +81,3 @@ function setupPeriodReminder() { ...@@ -80,7 +81,3 @@ function setupPeriodReminder() {
} }
} }
} }
function nothingChanged(dbChanges) {
return Object.values(dbChanges).every(changeArray => changeArray.length === 0)
}
\ 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