Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compared with valtio #5

Open
ysmood opened this issue Oct 25, 2024 · 0 comments
Open

Compared with valtio #5

ysmood opened this issue Oct 25, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@ysmood
Copy link
Owner

ysmood commented Oct 25, 2024

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

@ysmood ysmood added the documentation Improvements or additions to documentation label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant