Nested observable models trigger redundant updates in parent #281
Replies: 2 comments 2 replies
-
Hi @maximkrouk, I'm having a hard time understanding what exactly is wrong with the app you provided. Can you try creating a simpler reproduction of the problem with as few moving parts as possible? Ideally it would even just be a unit test that we could run to see a failure that you expect to pass. |
Beta Was this translation helpful? Give feedback.
-
The final API I'd like to achieve is somewhat like func bind(
_ model: Model,
into cancellables: inout Set<AnyCancellable>
) {
model
.observe(\.modelProperty, assign(to: \.viewProperty))
.store(in: &cancellables)
model
.observe(\.childModel, bind(to: \.childView))
.store(in: &cancellables)
// ...
} (I do basically have this implemented, but it requires split "tracking" and "onChange" closures for observe function)
structure for a topComponent.model = topModel
topComponent.observe {
middleComponent.model = middleModel // this will be triggered
middleComponent.observe {
bottomComponent.model = bottomModel
bottomComponent.observe {
bottomComponent.label.text = bottomModel.value.description // on this change, since all blocks are nested
}
}
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently I'm facing 2 issues with current observation API:
Redundant updates
observe
functionIf I use
@testable import
to access internalobserve
functionobserve
function with derived tracking and updatesobserve
function that applies transaction keys (including animations) is private and applies stuff only in tracking context (so derived updates doesn't get wrapped into transactionKeys.perform)DispatchQueue.main.async
, but as I'm writing it I'm starting to think that it won't fix animations since it will escape not only tracking context, but transactionKeys.perform as wellHere is a project that helps to reporduce the issue (didn't update the readme, so it mentions possible
DispatchQueue.main.async
fix, but seems like it won't work):https://github.com/maximkrouk/swift-navigation-test-repo/tree/main
I decided to start a discussion before opening a PR to figure out if I'm missing smth and maybe additions to the lib are not needed in that case c:
Beta Was this translation helpful? Give feedback.
All reactions