derive() with get(store, 'key') #714
sarimarton
started this conversation in
Ideas
Replies: 1 comment
-
Well, that's the thing. derive is too complex that we can no longer reasonably maintain. So, I can't accept adding features. I'm hoping to rather simplify it. So, for now, you should implement your idea as a third-party package and list in https://github.com/pmndrs/valtio/blob/main/docs/resources/libraries.mdx. btw, you might be interested in https://github.com/dai-shi/use-valtio, which does something for nested keys. I found that TypeScript typing was very tricky. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think it would be a nice complimentary addition to the
get()
function in derive, if we could specify a key so it turns into a key subscription.So instead of
It would be:
The benefit of the latter one is that it doesn't have unnecessary recalculation. The possible keys could be typed with typescript. I would also love to have nested keys there, e.g.:
Which is totally doable with typescript. This pattern focuses on the leaf values, which are typically the primary candidates for dependencies. It matches with Valtio's snapshot tracking logic as well, which also focuses on leaf values.
If there's positive feedback, i would gladly work on it. Unfortunately
derive()
is too complex to make this in userland without a huge amount of copy-paste, so I'm proposing it here.Beta Was this translation helpful? Give feedback.
All reactions