-
-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Valtio uses proxy to abstract away the need to declare the selector functions and state mutation functions. The abstraction is not without cost.
No middlewares
Proxy is a very high-level abstraction, it will make making a middleware correctly very hard.
At the time I write this, there's no middleware support from valito. Such as create a middleware to transform the state before it gets to next middleware (pipeline data). You can only subscribe the changes.
Hard to carry debugging information
If you mutate a state direct on its properties, you will not able to open a window to add extra debugging information to the mutation, for example:
function countAll() {
state.a++
state.b++
}When we call countAll, how can the devtools know what is happening?
With stalo you can do:
function countAll() {
set((state) => {
state.a++
state.b++
}, meta(countAll, "Count both a and b"))
}As you can see, we can pass extra info to middlewares for better reflection.
A lot of corner cases
Use abstraction like proxy has its price.
Like typing support issue: pmndrs/valtio#327
Like accidental proxy replacing: https://valtio.dev/docs/api/basic/useSnapshot
Cache key could refer previous value: pmndrs/valtio#925