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?
Preact - Next.js - Deno - SSR - SSG 💻
Open source 📂
Machine learning 🤖
Books 📖
Sport 🏃♂️
Nature 🌱
Focus on being useful. I contribute AMAP to the OSS community. Love learning by doing.
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]()).
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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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?
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...
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