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

feat: SolidJS port #16

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

feat: SolidJS port #16

wants to merge 2 commits into from

Conversation

arv
Copy link

@arv arv commented Feb 29, 2024

This is a basic SolidJS port

It does not yet figure out how to make Replicache ❤️ SolidJS. This is just a baseline to start from.

This is a basic SolidJS port

It does not yet figure out how to make Replicache ❤️ SolidJS. This is
just a baseline to start from.
@arv arv requested a review from aboodman February 29, 2024 11:03
@arv arv marked this pull request as draft February 29, 2024 11:03
Copy link

render bot commented Feb 29, 2024

@arv
Copy link
Author

arv commented Feb 29, 2024

Not intended to be merged to main.

Copy link

@aboodman aboodman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the re-rendering characteristics of this like? Seems like we should ideally only re-render the todo row that changed, not the entire list. Users often ask us to do better and re-render only the field that changed, but this doesn't seem practical.

In React, the model we've settled on is to have the container only subscribe to the keys. not the values. So the container re-renders if the list of todo IDs changes, but not their values. See reflect-draw for an example of this pattern.

I wonder if we could do something similar for Solid and/or if it's appropriate.

@arv
Copy link
Author

arv commented Mar 4, 2024

My plan was to look at the rerendering behavior after getting the basics working.

In Solid when you use the For component, it uses === for the individual elements of the array to determine if it needs to rererender the child. The outer array identity does not matter.

Users often ask us to do better and re-render only the field that changed, but this doesn't seem practical.

I agree that this does not seem to be practical in general. In Replicache we never mutate the data and we go a long way to ensure we minimize the number of clones. To support this deep mutation that would trigger minimal render updates the data needs to be cloned and mutated.

I do think that there might be some utilities that can be used in SolidJS apps that would map from a key to a solid store. And when the value of that key changes it would use solid's reconcile to update the store to only mutate the innards of the object. Strawman:

const item = createReplicacheValueStore(rep, key);
return <div>{item.description}</div>

item would be a reactive object. The value stored in Replicache be an object (array is fine too). It would subscribe to the key and item would be reactive just like a solid store.

We could also have version that supports scalars but then the item needs to be a function or an object with a value property.

Then we could maybe provide similar things for scan... and subscribe...

Anyway, I need to think more.

const todos = await todosByList(tx, listID);
return todos.sort((a, b) => a.sort - b.sort);
}, set),
const todos = subscribeStore(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting a bit more ergonomic.

@aboodman
Copy link

aboodman commented Mar 4, 2024

Your plan makes sense, thanks for explaining!

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

Successfully merging this pull request may close these issues.

2 participants