Computed getter for store?

I see I have two ways computed getter for store. 1. Using 'get' inside store. 2. Creating function outside store like I did for signal. What's better approach?
7 Replies
Alex Lohr
Alex Lohr2y ago
Whatever suits your need best. If you want to export the store, using a getter will be more elegant. If it is just inside a component, you can choose either way. That's the great thing about Solid – you have a lot of choice and there's always some helpful pattern to make your life easier.
musiclover
musiclover2y ago
Is adding setter inside store ok,too like this?
Alex Lohr
Alex Lohr2y ago
That would mean you would have to use store.setValue = newValue But you can add setValue: (v) => setMyStore('value', v) to have a setter function, which is less confusing and works just the same.
musiclover
musiclover2y ago
Ok, so I can use 'get', but to make setter, it's better setValue instead class's set accsessor. right?
Alex Lohr
Alex Lohr2y ago
Exactly. If you want to make everything settable, too, consider createMutable Ryan added this to cater for people coming from Vue.
musiclover
musiclover2y ago
Yes, I saw createMutable. but the docs say I should use just createStore...What's better? Isn't it ani-pattern to use createMutable?
Alex Lohr
Alex Lohr2y ago
Not at all. But createStore has a few tricks up its sleeves that let you set multiple properties in one setter call.
Want results from more Discord servers?
Add your server