My project is in Vue 3 (Composition API) w/ Pinia and SignalR
Here is an example of what I'm working with:
I have a parent object, let's call it Oven, and a child object called Bread.
There is a property in Oven called Bake which is of type Bread and represents the actively baking bread instance.
I have two pinia stores. One which stores all Oven instances and another which stores all Bread instances. These stores are initialized through separate API endpoints, so any instances of Bread kept in the Bake property within the Oven store will be different instances from the ones kept in the Bread store.
My questions are:
- Is there a way to directly reference an instance of
Breadfrom theBreadstore within anOvenobject. - If so, is that an appropriate solution?
- If not, would I then need to listen to a
Breadchanged SignalR event in both theOvenstore andBreadstore in order to update both instances? This seems inefficient to me, so I'm trying to find alternatives.
OvenandBreadobjects from a state management perspective to minimize the number of events I need to listen to. I'm looking more for architecture philosophy versus a working code sample if that helpsBreadStore. Instead of storing a full Bread object insideOven.Bakestore only thebreadIdand then create a property or getter that resolves the full Bread object from the Bread store. Your second question: Yes, this is best practice. Your third question: No, you are right with avoiding this.