Skip to content
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

"syncStateSummary" not @Published #18

Open
benguild opened this issue Sep 12, 2023 · 4 comments
Open

"syncStateSummary" not @Published #18

benguild opened this issue Sep 12, 2023 · 4 comments

Comments

@benguild
Copy link

I was looking at this library and noticed that this property, although useful, is not @Published.... So, in order to catch changes on it, one would need to monitor changes to a half dozen or so other properties.

It seems potentially wasteful (although not terribly) to calculate this in advance for publishing if not used, but it's also a hassle to monitor so many other properties.

Just wanted to ask if there was potentially a compromise here, or if you had best practices in mind regarding this. 😅

@benguild benguild changed the title "syncStateSummary" not published "syncStateSummary" not @Published Sep 12, 2023
@ggruen
Copy link
Owner

ggruen commented Sep 18, 2023

Hi @benguild,

The SyncMonitor class itself is an ObservableObject, so any property you include in a SwiftUI View (assuming you're using SwiftUI) will be updated when there's a change. You'll notice that the @Published properties in SyncMonitor are all private.

So, if you do:

@ObservedObject var syncMonitor: SyncMonitor = SyncMonitor.shared

then in your View include

syncmonitor.syncStateSummary

Then syncStateSummary will be updated when the sync state changes because syncMonitor itself will show that a change was published.

@benguild
Copy link
Author

Sorry for the delay! So, I guess the downside there is it'd recalculate the view whenever anything changes, even outside of the visual linked to "syncStateSummary" ...?

In this case it might be OK, but in others it might be less ideal depending on what's going on.

@ggruen
Copy link
Owner

ggruen commented Oct 21, 2024

Ok, now I apologize for the delay... My understanding is that, because SyncMonitor is an ObservedObject, that any public properties within it will behave, for practical purposes, like they're Published - that is, your syncMonitor variable will be what's updated (and thus trigger any UI updates), not the syncStateSummary property itself.

Are you using SyncMonitor outside of SwiftUI, and/or seeing an issue with syncStateSummary not updating (assuming you're still using this since I'm responding over a year later 😮 )?

@benguild
Copy link
Author

Right, so I guess the downside is that it requires observing the object rather than just that one property. It'd be nice to have that as a choice, but since the property is computed it would need to be stored, calculated initially, and then updated only when it changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants