DEV Community

Discussion on: Teaful: tiny, easy and powerful React state management

Collapse
 
eatsjobs profile image
Pasquale Mangialavori • Edited

Hi Aral. Nice work. I followed your previous implementation and I saw is very different from this one: you're using proxy now for example. Could you tell me why? Have you found the previous implementation limited somehow?

Collapse
 
aralroca profile image
Aral Roca

Thanks! Previously, hooks were generated according to store properties (useCart, useUsername...). It was useful only at the first level, but there could be many conflicts in nested properties.

The implementation has also changed so that instead of creating a Provider for each property (many contexts) we make our subscription system, being more scalable for large stores.

Changing it to a Proxy adds the possibility of using hooks for each store property even if it is very nested. Making the component that has useStore.cart.price() only rerender when the cart price is updated and not when other properties of the store are updated.

It even allows you to access an item in an array that you have in the store and the component will only rerender if that item changes (useStore.items[index]()).

Here there is a tweet I explain a little bit the evolution of this lib twitter.com/aralroca/status/145697...

Collapse
 
eatsjobs profile image
Pasquale Mangialavori

I was asking cause I found it useful and I wrote and implementation very similar using useReducer instead of useState and splitted the dispatch in a different context. I will share it with you soon