最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

vue.js - Vue 3 Pinia State and Architecture Best Practices For ParentChild Relationships With SignalR - Stack Overflow

matteradmin1PV0评论

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.
Post a comment

comment list (0)

  1. No comments so far