-
Notifications
You must be signed in to change notification settings - Fork 115
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
[Woo POS] Make POS aggregate model Observable #15059
[Woo POS] Make POS aggregate model Observable #15059
Conversation
This adds a thin Observable layer on top of the underlying combine code
Now that we use `Observation` on the POS aggregate model, we should inject/fetch it with @Environment and use @State to hold it.
Generated by 🚫 Danger |
…to issue/14869-make-pos-aggregate-model-observable
|
@@ -349,7 +367,10 @@ private extension PointOfSaleAggregateModel { | |||
onOnboardingCancellation = onCancel | |||
return viewModel | |||
} | |||
.assign(to: &$cardPresentPaymentOnboardingViewModel) | |||
.sink(receiveValue: { [weak self] onboardingViewModel in |
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.
Do you think some of the memory leak issues could get resolved this way? I treated assign
as a syntaxic sugar to sink
but some of our memory debugger observations are pointing to these assignments 🤔
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.
Possibly... but probably not. assign(to: on:)
keeps a strong reference though, perhaps it's worth looking for that deeper in the codebase?
If you instead implemented MyModel with assign(to: lastUpdated, on: self), storing the returned AnyCancellable instance could cause a reference cycle, because the Subscribers.Assign subscriber would hold a strong reference to self. Using assign(to:) solves this problem.
–assign(to:)
docs
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.
@staskus Replacing the publishers and associated sink
calls with simple properties might help (see my other comment) but it probably won't be practical to break it for the Payments code, because that's used right down at the StripeCardReaderService
level.
@staskus @iamgabrielma @jaclync only requires one review, but I want to tag all of you in these changes for visibility. Future work on the cards:
|
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.
Thanks! I'm happy will be using the most modern recommended APIs 👍
I read the migration docs and the changes follow the plan.
I also tested products, variables products, floating bar actions, simple product alert, reader connection/disconnection, card payment, cash payment, email receipts, and a couple of error states. It all works as expected. I only noticed the detail you mentioned about ghost cells visible when doing the pull to refresh.
Do you think we should do anything about this? For example, rework the item list state so it could be observed more granularly. Or is it not worth it? Edit: Answered in this PR #15059 as well. I'm glad we can use |
Part of: #14869
Merge after: #15048
Description
This PR makes the POS Aggregate Model
@Observable
, and switches over to@Environment
and@State
to hold it.Observation
uses macros and property wrappers to keep track of which views depend on which properties, then only redraw the dependent views when the property's value changes.Previously, with
ObservableObject
, any view which used the aggregate model would be redrawn whenever any of its@Published
properties changed. This meant that all of the POS was redrawn whenever any published property changed, because the Dashboard view would be redrawn and that would cascade down the heirarchy.There are no changes to expected behaviour in this PR, and the properties we observe are still mostly backed by Combine publishers.
It may be possible to observe some reduction in redraws of the whole
PointOfSaleDashboardView
, where redraws begin to localize to the views which depend on something that's changed. This is limited though, because state changes are still frequent and (for example) the Dashboard view still relies on the item list state, so any changes to that state will redraw everything.Testing information
It's worth testing broad functionality of the POS, checking that it behaves as you expect. This testing doesn't need to be especially deep; there are more PRs to come where we'll get further in to the detail.
RELEASE-NOTES.txt
if necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: