"Zooming in" on shared keys for smaller slices of observable state #200
jessetipton
started this conversation in
Ideas
Replies: 0 comments
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.
-
In our codebase, we're finding more and more that we'd like to be able to "zoom in" on the value published by a given shared key in order to observe only a small piece of the value it shares.
As an example, imagine a struct representing a user's account that contains many, many properties:
And we'll assume some shared reader key exists that lets us observe the latest account value across the application.
To illustrate the potential value we see here, imagine a simple view that just wants to show the current account's email address in in a list:
My understanding is that any new
Accountvalue yielded by the.accountkey will cause the view body to recompute. We'd also expect that if we were to move the@SharedReader(.account) var accountproperty to anObservableobject (e.g. a view model) or a TCA reducer's state, any change to theAccountwould result in the view body recomputing as well.What seems reasonable to us is that there would be some way to observe just the data we need from the key, and reap whatever efficiency gains would come from that. Essentially, something like this:
We'd expect that the key returned by this imagined
map(_:)function would only yield new values when the account's email property changes. Any newAccountvalues that are updating other properties or provide the sameemailvalue would just be ignored.Would anyone else find this a useful addition to the library? Are there costs or complexities we're overlooking in assuming this should be possible?
Beta Was this translation helpful? Give feedback.
All reactions