Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create multiple instance of state ? #370

Open
akbaramd opened this issue Nov 5, 2023 · 7 comments
Open

How to create multiple instance of state ? #370

akbaramd opened this issue Nov 5, 2023 · 7 comments

Comments

@akbaramd
Copy link

akbaramd commented Nov 5, 2023

i use mdi component and in one page new multiple instance of state in each tab ?
how i can handle this?

@akbaramd
Copy link
Author

thank your for your response :/

@StevenTCramer StevenTCramer reopened this Nov 16, 2023
@StevenTCramer
Copy link
Collaborator

@akbaramd I enjoy sarcasm :)

ChatGPT

The question appears to be about using a Material Design Interface (MDI) component in a Blazor application, where multiple instances of a specific state are created within each tab of the interface. The user is seeking guidance on how to manage this scenario effectively.

In Blazor, each component can have its own state, but when dealing with multiple instances of the same component (like tabs in an MDI), managing state becomes more complex. The user might be facing challenges with state synchronization across multiple component instances or isolating state for each instance.

To address this, you could consider the following approaches:

1. **Scoped State**: Implement a state that is scoped to each tab. This means each tab will have its own independent state, preventing interference between tabs.

2. **Centralized State Management**: Use a centralized state management pattern (like BlazorState) to manage the state. This approach allows you to have a single source of truth for your state, and each tab can subscribe to state changes as needed.

3. **Event Handling and Propagation**: Ensure that events that trigger state changes are handled correctly. If a state change in one tab needs to reflect in another, this should be managed through event propagation or shared state management.

4. **State Initialization and Cleanup**: When a new tab is opened, initialize its state correctly. Similarly, when a tab is closed, ensure any cleanup or state deregistration is performed to avoid memory leaks or stale state issues.

5. **Testing**: With multiple states and interactions, it's important to thoroughly test the components. Use your testing framework (like Fixie, which you're familiar with) to write tests that simulate the various interactions and state changes.

In summary, the question is about managing multiple instances of state within an MDI component in a Blazor application. The solution involves considering the scope of the state, centralizing state management, handling events properly, and ensuring correct initialization and cleanup of state in each tab.

@aboudoux
Copy link

Indeed, an evolution of the store that would allow obtaining a State by an identifier rather than by a Type would be ideal.

@StevenTCramer
Copy link
Collaborator

@aboudoux Please explain? There is only one State per type. If you want to create a collection of things in that state you can. But there isn't a collection of the States by type. And I do not believe there should be. If you can give me a use case and show me some sample I will be happy to look in to it.

Currently the Type is the identifier.

@aboudoux
Copy link

If I have a multi-document application in the form of tabs, and each sub-tab also has sub-tabs, I have no choice but to manage a collection of States within a State and pass each State through my actions.

This works well, except that today I am stuck because I am creating a chat space, and I would like all the corresponding States of all connected users to refresh with each message post.

This can be done quite easily by publishing our action to a multicast Bus, but the problem is that I need to find the concerned State for each user. However, if I have a collection of states within a collection of states, I need a way to find the target State, and I can only do this if each State has a defined identifier (like the chat identifier, for example).

@aboudoux
Copy link

image

Here a screenshot to explain what I mean

@aboudoux
Copy link

aboudoux commented Apr 23, 2024

Here, the green tabs are all the same state type, and within each tab, there are sub-states. In the Conversation(s) section, I can have 2 Chats. I want that when I post a message, another user connected to this can see it. While I can easily send the action between users, it's impossible for me to find the instance of the other user's state based solely on the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants