How to split codes in store to multiple files?

I have a huge store. And, I would have many createEffect at each value in store. I want to split to seperate files like this. Does this work?
3 Replies
Brendan
Brendan2y ago
For sure you could put createFoo in its own file, export it and then import that into the top of your createHugeStore file ...just like with any javascript functions. ...as long as you are storing your state in something reactive like a signal or store. Your effects shown in the screenshot will never re-run since state is not stored in a reactive primitive (eg signal) at the time you are creating the effect.
musiclover
musicloverOP2y ago
I found having a lot of singals in store is slow. So I want to use single store with createRoot. But I can't see how to split to multiple files if store is huge like createEffect.
Brendan
Brendan2y ago
I don't think having lots of signals would be any slower than a store - the store might just be more convenient and extendable than having to create lots of specific signals. Anyway there are lots of ways you can do this. But regardless, you need to get the state into something reactive before you create any effects. It really depends on how complex each of these state items (eg Foo) is - and how you want to allow it to be updated. If Foo is complex enough, you may want it to create its own store internally. In that scenario createHugeStore might just be assembling an "index" of child stores (potentially with their own mutation functions). It is difficult to provide guidance without knowing the structure of the actual data you want to manage, and how you want to control any changes to that data. The best way might differ depending on the specific data item. In other words - give me a real example of one of these data items, where the data comes from and how/if you want the application to be able to update it.
Want results from more Discord servers?
Add your server