Performance impact of computed property #2702
Unanswered
marcuswu0814
asked this question in
Q&A
Replies: 1 comment 4 replies
-
@mbrandonw Soory to bother you, will version 1.7 enhance this use case? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
According to Doc - Performance/Store Scoping, I know about the scoping child store of computed property will trigger computed every time when parent state changed.
In our development context, the existing class
ViewModel
/ViewController
usingRxSwift/RxCocoa/RxCombine
to bind the data into view.We have a helper function like:
The
ViewModel
andViewController
like:And the
Reducer
like:The full executable project is here, and my questions is:
Q1: Is
ViewStore(observe:)
kind of scoping child state?The above code I wrote is straightforward for transform a state into observable, but current concern is, the computed property will be trigger by
timerTicked
action and the state changed. So should I avoid this strategy for my use cases?Q2: If I refactor computed property into mutating function, is the following code best practices?
I try to improve the recalculate, using a mutating function for
State
like:But:
onChnage(of:)
modifier their and should remember to invokestate.caculate()
.a
andb
, should includec
ord
, the modifier much more redundant, is there have any advance for this situation?Beta Was this translation helpful? Give feedback.
All reactions