Replies: 2 comments 2 replies
-
Please call For previous value, you need to store it on your end. This minimal API design is a kind of philosophy and it's the same in Valtio. (Zustand doesn't follow for a historical reason.) |
Beta Was this translation helpful? Give feedback.
-
While I agree with the minimalist approach, I think we need to keep in mind what the purposes of minimalism are and consider if a change would compromise its benefits. In this case I think the answer is no. Let's look at some of the aspects where it might be affected:
So I think this change would still fit well in a minimalist API design. Moreover, I think semantically it'd just be natural and helpful if the store tell you this |
Beta Was this translation helpful? Give feedback.
-
Currently
store.sub
function is defined as follow, where the listener doesn't receive any parameter:If I want to get the atom value inside the listener, I have to call
store.get(thatAtom)
. It could be simplified by just passing the current atom value to the listener.Another common need is to access the atom's previous value before the change happened, which is currently not possible unless I manually cache the atom value elsewhere, such as with another atom. I think it would make sense to pass the previous value as the second parameter (after the current value) to the listener, so you can ignore it if you don't need it.
So the suggested definition would be as follow:
Is this feasible? Any shortcoming that I haven't been aware of? I can create a PR if it makes sense.
Beta Was this translation helpful? Give feedback.
All reactions