Selector Ergonomics #1247
Replies: 2 comments 4 replies
-
Hello! You're right that it is a good practice to only observe what's needed for a If you define: extension App { // Your view
struct ViewState: Equatable {
let a: String
let b: String
let c: String
init(state: AppState) {
self.a = state.a
self.b = state.b
self.c = state.c
}
}
} You can then use You can find more information on the subject here for example. |
Beta Was this translation helpful? Give feedback.
-
WithViewStore(
self.store.scope(state: { ($0.a, $0.b, $0.c) }),
removeDuplicates: ==
) { viewStore in
…
} @tgrapperon's mention of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
It often happens for performance reason that we want our component to observe only a part of our store so that it is not redrawn every time other attributes it doesn't depend on, change.
This is looking good when
MyComputationalHeavyComponent
relies on one variable from the store, but that doesn't seem to scale well ergonomically ifMyComputationalHeavyComponent
relies on multiple parameters:A bit similar to how Redux selectors work with objects, I would hope
WithViewStore
being a variadic function and so, it would accept multiple parameters to avoid nested components:I know the whole project has worked on lot on ergonomics, so I was wondering if I was missing something and something similar already exists or if that would be worth that I open a PR.
Beta Was this translation helpful? Give feedback.
All reactions