-
Notifications
You must be signed in to change notification settings - Fork 55
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
Svelte Support #24
Svelte Support #24
Conversation
This reverts commit e81be59.
Awesome stuff @zsaquarian ! If I understand the Ideally (this is similar to how the React / Vue bindings work), a refresh would only be triggered when the actually used (subscribed) data changes. I suppose this is what you mean why we'd need to use Svelte Stores, right? Would it be possible to create a store for every "atom" in |
Thanks! :)
Yes
I didn't really understand what you mean by subscribed data vs. any data. The If so, then it doesn't. I just checked it.
Perhaps I should have been clearer.
I tried that originally, but it seems svelte will only rerender a component if the store is directly used in that component. This basically means that the |
Yes, this is what I meant. If it doesn't rerender now, I think that's because there's no other component using |
I think we can make this work using the Reactive library. Could you try something like this? (I haven't tested it yet)
In your component:
|
Unfortunately no :( Even if we make it a writable store (so we can modify it), we would still have to do something like this: $store.todos = [...$store.todos, newItem]; Which throws Also, I don't really see the problem with rerendering a component? Am I missing something? |
That error is expected, the correct pattern for that would be
Performance wise, you would want to make sure only the relevant component(s) rerender if the synced data change. Especially when multiple developers / projects will depend on the library |
No, since there is no assignment there.
Ah OK. I understand. Also, fortunately, I seem to have made it work! Svelte has an 2021-11-12.22-37-28.mp4Edit: the repetition at the top is because I am inserting that text into |
Cool! I just gave it a shot as well, see https://github.com/YousefED/SyncedStore/tree/svelte. What do you think? I'd move |
Awesome!
I agree. Thanks! |
This has been published in 0.3.4 and PR #25 |
This PR adds support for svelte. Unfortunately, because svelte reactivity is based on assignments, we need a dummy function. Other than that, usage is identical. We could also use svelte stores, but that would need a rewrite of the entire library as the
crdt
object would need to become a store.