From 124f6cfce702dc40dfac1b16c72884cc9cbbb5ab Mon Sep 17 00:00:00 2001
From: Julia Friesel <julia.friesel@gmail.com>
Date: Mon, 15 Oct 2018 09:34:07 +0200
Subject: [PATCH] Use nothing-changed helper in home to prevent unnecessary
 render

---
 components/home.js      | 4 +++-
 helpers/db-unchanged.js | 3 +++
 lib/notifications.js    | 5 +----
 3 files changed, 7 insertions(+), 5 deletions(-)
 create mode 100644 helpers/db-unchanged.js

diff --git a/components/home.js b/components/home.js
index 56e59e8d..364ba27c 100644
--- a/components/home.js
+++ b/components/home.js
@@ -11,6 +11,7 @@ import { getOrCreateCycleDay, getCycleDaysSortedByDate } from '../db'
 import { getFertilityStatusForDay } from '../lib/sympto-adapter'
 import styles from '../styles'
 import AppText, { AppTextLight } from './app-text'
+import nothingChanged from '../helpers/db-unchanged'
 
 export default class Home extends Component {
   constructor(props) {
@@ -32,7 +33,8 @@ export default class Home extends Component {
     this.cycleDays.addListener(this.updateState)
   }
 
-  updateState = () => {
+  updateState = (_, changes) => {
+    if (nothingChanged(changes)) return
     const prediction = this.getBleedingPrediction()
     const fertilityStatus = getFertilityStatusForDay(this.todayDateString)
     this.setState({
diff --git a/helpers/db-unchanged.js b/helpers/db-unchanged.js
new file mode 100644
index 00000000..4625a804
--- /dev/null
+++ b/helpers/db-unchanged.js
@@ -0,0 +1,3 @@
+export default function (dbChanges) {
+  return Object.values(dbChanges).every(changeArray => changeArray.length === 0)
+}
\ No newline at end of file
diff --git a/lib/notifications.js b/lib/notifications.js
index 0eab38a3..8c1934dc 100644
--- a/lib/notifications.js
+++ b/lib/notifications.js
@@ -5,6 +5,7 @@ import Moment from 'moment'
 import { settings as labels } from '../components/labels'
 import { getOrCreateCycleDay, getBleedingDaysSortedByDate } from '../db'
 import cycleModule from './cycle'
+import nothingChanged from '../helpers/db-unchanged'
 
 export default function setupNotifications(navigate) {
   Notification.configure({
@@ -80,7 +81,3 @@ function setupPeriodReminder() {
     }
   }
 }
-
-function nothingChanged(dbChanges) {
-  return Object.values(dbChanges).every(changeArray => changeArray.length === 0)
-}
\ No newline at end of file
-- 
GitLab