Closed wrong7 closed 1 month ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
valtio | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Apr 22, 2024 1:15pm |
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Thanks for the suggestion.
We have a subtle design constraint.
Basically, we would like to provide only primitive capabilities and have utils outside. (and Valtio Labs https://github.com/valtiojs is for it.)
Due to this, I don't feel like having both subscribeKey and subscribeKeys in valtio/utils
. Our options are:
valtiojs/*
valtiojs/*
and remove subscribeKey from valtio/utils
in v2valtio/utils
in v2 and add subscribeKeys to valtio/utils
(in v1, deprecating subscribeKey)Another note is that we don't generally recommend using subscribeKey
. We (or at least I) prefer subscribe
instead.
The current subscribeKey
is like a reference implementation. So, I probably like the first option and we are free to add subscribeWithPath(s)
if we want.
I'm not sure if I'm happy with returning the previous value. It can be a proxy object, and mutable. I think we should snapshot
it, but that doesn't seem very good design. Yeah, this make me think we should go with the second option.
We are about to release v2 sometime soonish.
Let's consider subscribeKeys
is for valtiojs org.
Let me know if anyone is interested in working on it as well as subscribePath(s)
.
We are about to release v2 sometime soonish. Let's consider
subscribeKeys
is for valtiojs org. Let me know if anyone is interested in working on it as well assubscribePath(s)
.
Hey👋, I'm interested in contributing!
Hey👋, I'm interested in contributing!
Sent an invitation! You want to also join our Discord server(s) so that we can discuss there if you want.
嘿👋,我有兴趣做出贡献!
已发送邀请! 您还想加入我们的 Discord 服务器,以便我们可以在那里进行讨论(如果您愿意的话)。
Okay, I've accepted the invitation and joined Discord!
Summary
New utility function based on the current
subscribeKey
that allows subscriptions to multiple properties of a proxy.This PR also adds an optional second argument to the callback function from
subscribeKey
, and therefore the newsubscribeKeys
to provide the previous value of the changed property.I felt this utility was needed when I had to subscribe to a proxy that changed multiple properties at once, and I needed those changes to execute a single callback.
Usage
Check List
yarn run prettier
for formatting code and docs