1

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:

  1. Is there a way to directly reference an instance of Bread from the Bread store within an Oven object.
  2. If so, is that an appropriate solution?
  3. If not, would I then need to listen to a Bread changed SignalR event in both the Oven store and Bread store in order to update both instances? This seems inefficient to me, so I'm trying to find alternatives.
4
  • Could you please add the relevant code snippets? Commented Apr 3, 2025 at 14:53
  • There isn't really any relevant code snippets. I'm more or less asking how I should structure the relationship between the Oven and Bread objects 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 helps Commented Apr 3, 2025 at 15:12
  • About your first question: Yes, you can and should reference the shared instance from the BreadStore. Instead of storing a full Bread object inside Oven.Bake store only the breadId and 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. Commented Apr 3, 2025 at 15:15
  • Great, thank you Commented Apr 3, 2025 at 15:42

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.