How to make custom getter for store?

Can I do it like this? I don't guess the getState function would be reactive. is it possible?
13 Replies
lxsmnsyc
lxsmnsyc2y ago
it is reactive, the error is about the types not being compatible
musiclover
musiclover2y ago
I just changed screenshot. The case is also possible?
lxsmnsyc
lxsmnsyc2y ago
you need to define the type for createStore as Record<string, number[]> or maybe key: keyof typeof state
musiclover
musiclover2y ago
So Solid detects which property is reactive even key is function parameter?
lxsmnsyc
lxsmnsyc2y ago
all properties of a store is reactive
musiclover
musiclover2y ago
But I'm not doing like 'state.colors[0]', I'm doing getState('color', 0)
lxsmnsyc
lxsmnsyc2y ago
basically as long as you access a property of the store, you're telling it to "subscribe if there's a tracking context like createEffect" the same concept applies to props doesn't matter state.colors and state['colors'] are the same Solid's reactivity isn't compile-time, it's runtime Proxies makes this happen
musiclover
musiclover2y ago
I have nested properties. In this case, Can I make custom single getter?
lxsmnsyc
lxsmnsyc2y ago
why not I have a question though, why the need for a getter when you can access it directly
musiclover
musiclover2y ago
Because it's my current situation. I have same properties as global or in pages. Currently, I can't find best solution..
lxsmnsyc
lxsmnsyc2y ago
yeah I mean instead of abstracting it with getState why not access the state directly is this just code preference
musiclover
musiclover2y ago
Because I'll have much more properties in global, page. Checking all "state.activeGlobalProps.includes()" always is so tedious. I have 70 props in each pages, also global one.
lxsmnsyc
lxsmnsyc2y ago
I think I'm missing something out but is there really a huge difference if you remove getState from your code the way getState is implemented, you'll have difficulties having the correct type inference like right now, you're experiencing type errors