Is it a bad idea to use one store per keyed object instance? #2352
-
I am thinking through how I want to design my data store in a new app. My app has many models coming from the backend (customers, invoices, comments, etc). Would it be a bad idea to create a store instance for each instance of customer? For example, instead of useCustomersStore which houses an array of customers, I am thinking of having useCustomerStore which is specific to each customer:
I have potentially 10k+ customers which could be loaded in this way, so thus it would create 10k+ keyed stores customer/1, customer/2, customer/3 etc. The reason I would like to do this is to leverage computed properties at the row level, for example contactInfo getter above. I also prefer having a save() action on the individual customer, rather than a save(instance) action on a list type store. Thoughts? Is this a bad idea? Are there better ways to accomplish what I'm thinking? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, it's usually a bad idea. You have other patterns to do this kind of things like classes (with custom serializers if doing SSR) or passing the id as an argument |
Beta Was this translation helpful? Give feedback.
Yes, it's usually a bad idea. You have other patterns to do this kind of things like classes (with custom serializers if doing SSR) or passing the id as an argument