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

Shallow compare in reactive bindings #2959

Closed
ghost opened this issue Jun 5, 2019 · 1 comment
Closed

Shallow compare in reactive bindings #2959

ghost opened this issue Jun 5, 2019 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 5, 2019

Here's an example:
https://svelte.dev/repl/908698aa30ad46ba92569e5060e6f73b?version=3.4.4

If you press either of the buttons, the reactive block will be re-evaluated, even though it only depends on the subset of state object. In react, afair, they use shallow compare on component side to determine if relevant pieces of state changed, and this stops redux from triggering render on every state change.

I understand that svelte maybe was not intended to be used with reducers, but I'm currently working on a toy project which gives me an impression that svelte can actually work with reducers very well and even be more convenient than react by using reactive bindings to pieces of state.

My current workaround here is to compare manually like this:
https://svelte.dev/repl/c9152261372e4d109352e5ce7da2271d?version=3.4.4

Is there anything to automate these compares or maybe plans to support this in future?
This feature seems not very complicated, but will make svelte more appealing to redux fans.

@ghost
Copy link
Author

ghost commented Jun 7, 2019

Woops, I had no idea this section of tutorial may be helpful, so never looked inside until today.
This is enough for my usecases, so I'm closing the issue:

<svelte:options immutable={true}/>

This issue was closed.
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

0 participants