Skip to content
This repository was archived by the owner on Mar 2, 2025. It is now read-only.

Allow merging state in multi-app environments #12

Open
eliias opened this issue Dec 4, 2022 · 1 comment
Open

Allow merging state in multi-app environments #12

eliias opened this issue Dec 4, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@eliias
Copy link
Owner

eliias commented Dec 4, 2022

Problem

For certain setups, we must support "merging" state that is extracted from several render calls. For example, multiple Vue apps using Apollo or a state management library will produce a normalized hash map of entities. We should provide a simple (optimistic) merge algorithm for multi-apps, where we assume no conflicts, but merge into a single client.

@eliias eliias self-assigned this Dec 4, 2022
@eliias eliias added the enhancement New feature or request label Dec 4, 2022
@eliias
Copy link
Owner Author

eliias commented Dec 8, 2022

This requires shared state between one or more views in Rails. We need to aggregate all states and merge them optimistically (last one wins). We can extract the state help (isorun_state) into the parent view/layout to avoid injecting more than once.

An app that is rendered with a given state_id, will not render the state immediately, but persist the state returned by the SSR function in a shared store, and isorun_state will simply fetch and merge all the states present in this variable.

# app_frame.html.erb
<%= isorun_app("sidebar", state_id: :apollo) %>
<%= isorun_app("main", state_id: :apollo) %>

# layout.html.erb
<%= isorun_state("apollo") %>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant