Skip to content

Compared with valtio #5

@ysmood

Description

@ysmood

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions