question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow reactivity inside functions

See original GitHub issue

When I use a function inside my template, eg <p>{getUserName()}</p>, and getUserName() is using a reactive variable, the template is not updated when the reactive variable changes. I guess this is due to the compiler not analyzing the function and looking which variables it depends on. But, if I use an inline function inside the template (as demonstrated in the below), it updates just fine.

https://svelte.dev/repl/df444c2dfa5240ae9c8c203aaabdcd61?version=3.9.1

How hard would it be to add this feature?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
buhrmicommented, Aug 27, 2019

@PaulMaly wow, thanks for that. I guess that solves this issue in a “sufficiently elegant” way 😃

3reactions
PaulMalycommented, Aug 27, 2019

@buhrmi Please check workaround for this feature: https://svelte.dev/repl/39fcb67d8041423e84d7c08da75b05de?version=3.9.1

Basically, you can think about regular function call inside of your template as about pull reactivity and reactive declarations as push reactivity. Both methods we need in some cases.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 3 Basic reactivity | Mastering Shiny
Reactive expressions are important because they give Shiny more information so that it can do less recomputation when inputs change, making apps more...
Read more >
Use reactive expressions - R Shiny - RStudio
This lesson will show you how to streamline your Shiny apps with reactive expressions. Reactive expressions let you control which parts of your...
Read more >
5 Reactive functions | Building Web Apps with R Shiny
5.2 reactive()​​ This means that whenever an input inside that function changes, the code will run and update the value of data() ....
Read more >
How does Svelte reactivity work inside functions?
I have isolated what I think is at least one of my main issues. When bind:ing a variable to a checkbox, the reactivity...
Read more >
The Magic Behind Reactivity - Effects - Ryan Chandler
In this post, I'll be creating an effect function that will allow us to react to changes on the Proxy and update the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found