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

SSR support #16

Open
jason89521 opened this issue May 23, 2023 · 1 comment
Open

SSR support #16

jason89521 opened this issue May 23, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jason89521
Copy link
Owner

jason89521 commented May 23, 2023

My current idea is to hydrate based on different accessors. The API might look like this:

const postAdapter = createPaginationAdapter({});
const postModel = createModel(initialModel);
const getPostById = postModel.defineAccessor('normal', {
    // configuration
});

function Page({ post }) {
    useHydrate(getPostById(post.id), () => {
        postModel.mutate(model => {
            postAdapter.upsertOne(model, post)
        })
    })
}

The useHydrate function will record the provided accessor and execute the function if the current accessor hasn't been recorded yet. When the accessor changes, it removes the previously recorded one and records the new one. In the example above, this ensures that when post changes, we can update the model in real-time.

However, this approach has a drawback. Developers need to place useHydrate at the top level of the component tree to manage accessors centrally and avoid duplicate accessors being passed. Additionally, attention needs to be paid to which models need to be hydrated on which pages to prevent data from being missed.

@jason89521 jason89521 added the enhancement New feature or request label May 27, 2023
@jason89521 jason89521 added the help wanted Extra attention is needed label Jun 14, 2023
@jason89521
Copy link
Owner Author

jason89521 commented Jun 30, 2023

Should provide a way to create new state in server to prevent from mutating the global model's state directly in server. It would cause state pollution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant