-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix discarded notification observers in StatsWidgetsStore #20995
Fix discarded notification observers in StatsWidgetsStore #20995
Conversation
📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I wrote elsewhere, +1 for using selectors over blocks since this way iOS does the lifecycle management for us 👏
There are already tests setup for this object. This could be a good occasion to add to them.
UserDefaults(suiteName: WPAppGroupName)?.setValue(AccountHelper.isLoggedIn, forKey: AppConfiguration.Widget.Stats.userDefaultsLoggedInKey) | ||
|
||
if !AccountHelper.isLoggedIn { | ||
HomeWidgetTodayData.delete() | ||
HomeWidgetThisWeekData.delete() | ||
HomeWidgetAllTimeData.delete() | ||
if !AccountHelper.isLoggedIn { | ||
HomeWidgetTodayData.delete() | ||
HomeWidgetThisWeekData.delete() | ||
HomeWidgetAllTimeData.delete() | ||
|
||
UserDefaults(suiteName: WPAppGroupName)?.setValue(nil, forKey: AppConfiguration.Widget.Stats.userDefaultsSiteIdKey) | ||
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.todayKind) | ||
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.thisWeekKind) | ||
WidgetCenter.shared.reloadTimelines(ofKind: AppConfiguration.Widget.Stats.allTimeKind) | ||
} | ||
UserDefaults(suiteName: WPAppGroupName)?.setValue(nil, forKey: AppConfiguration.Widget.Stats.userDefaultsSiteIdKey) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One could DRY and this a tiny bit by storing the UserDefatuls
instance and adding an early return
let defaults = UserDefaults(suiteName: WPAppGroupName)
defaults.setValue...
guard !AccountHelper.isLoggedIn else { return }
...
🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 66ff6fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to what Gio said – thanks for making it so this can't be used wrong!
Relates to #20994.
This PR changes to use
StatsWidgetsStore
as notification observers, so thatNSNotificationCenter
automatically unregister the observer when the store instance is released.StatsWidgetsStore
is currently a singleton, so technically there is no issue with current code and this PR has no effect at all to the app. However,StatsWidgetsStore
may get to escape from theStoreContainer
singleton and the issue with notification observers will arise then. Also, we should not discard notification observers anyways.Regression Notes
Potential unintended areas of impact
None.
What I did to test those areas of impact (or what existing automated tests I relied on)
Log in and log out.
What automated tests I added (or what prevented me from doing so)
None.
PR submission checklist:
RELEASE-NOTES.txt
if necessary.UI Changes testing checklist: N/A