Better HN
topnewbestaskshowjobs
Log inSign up

opensas

47 karma · joined Jan 10, 2012 (14y ago) · 35 submissions

Submissions

comment 3y ago · link · parent

the inconsistency comes from the fact that this reactivity, triggered from inside a function, is not taken into account to build the dependency graph and ultimately decide in which order to process the statements

comment 3y ago · link · parent

top level variables are reactive even when updated inside a function, just give it a try:

https://svelte.dev/repl/44e3aece18294ddb834bcdfb4394af48?ver...

` <script>

  let name = 'world';

  const flip = () => name = name === name.toUpperCase() ? name.toLowerCase() : name.toUpperCase()

  $: console.log({ name })
</script>

<h1>Hello {name}!</h1>

<button on:click={flip}>flip!</button> `

comment 3y ago · link · parent

> The $ label is one technical reason why I would be hesitant to adopt Svelte for larger projects. It's a core part of Svelte that you can't always avoid, and I think the potential for introducing bugs through it is high to start and very high at scale.

The reactivity system in Svelte is really a joy to use, once you get used to it there's no turning back.

But the author did hit one of the ugliest pain points about it. Svelte can NOT correctly infer transitive dependencies when the variable being updated is inside a function. Meaning that the variable itself will be reactive (it will be invalidated every time it's assigned, even inside a function) but Svelte is not using that information to build the dependency graph, and falls back to the order in which the reactive blocks were defined, which may or may not be right.

I created this issue https://github.com/sveltejs/svelte/issues/5190 a couple years ago documenting it.

It's not so common, but when it bytes you it's pretty nasty.

The workarounds I found are the following

These are the workarounds I found:

- a repl with the issue: https://svelte.dev/repl/640736d3c91d40d3971afcc3eef8b25e?ver...

- workaround 1: manually reorder statements, need to figure out by yourself (and maintain!) the dependency graph: https://svelte.dev/repl/3ecd6aa918e045999db32d379270fc1c?ver...

- workaround 2 (my favorite): provide a redundant update as "hint" to tell the compiler that setY updates y: https://svelte.dev/repl/cbf98bb35f5e4dd4b037d13254853c90?ver...

(thanks to TylerRick for this: https://github.com/sveltejs/svelte/issues/5190#issuecomment-...)

in practice it means to do something like: `$: { setY(x); y = y };`

- workaround 3: put the update operations in order in a single block (it's just the workaround 1 with improved legibility, IMHO): https://svelte.dev/repl/074df362bb934312bbe6fd3aeccab771?ver...

I still think we could do better, at least explaining the issue and how avoid to fall into it (perhaps some linting warning?)

But I really hope svelte developers start considering this an issue to solve, it's inconsistent (meaning the variable is reactive but that reactivity is not taken into account to order the operation in "topological order" (Hey, I learnt about that from one of Rich's presentations, see https://rethinking-reactivity.surge.sh/#slide=19) and as I said before, in the rare occasions you stumble upon it is not so easy to understand what's going on.

4.

A few ideas to foster Ubuntu edge founding(opensas.wordpress.com ↗)

2 points · by opensas · 13y ago · discuss

5.

Publish your own geocoded web services with CartoDB(opensas.wordpress.com ↗)

2 points · by opensas · 13y ago · discuss

6.

Using OpenRefine to geocode your data using Google and OpenStreetMap API(opensas.wordpress.com ↗)

1 points · by opensas · 13y ago · discuss

7.

Journey to the open data jungle with OpenRefine, CartoDB, Leaflet and Javascript(opensas.wordpress.com ↗)

1 points · by opensas · 13y ago · discuss

8.

Sharing you JavaScript Ninja secrets: Run your jasmine tests on jsFiddle(opensas.wordpress.com ↗)

1 points · by opensas · 13y ago · discuss

9.

Live hot-code reloading with Chromium browser on Linux(opensas.wordpress.com ↗)

2 points · by opensas · 13y ago · discuss

10.

Troubleshooting Javascript & Backbone - part 1(opensas.wordpress.com ↗)

3 points · by opensas · 13y ago · discuss

comment 14y ago · link · parent

great article...

12.

Deploying Play Framework 2 apps, with Java AND Scala, to Openshift(playlatam.wordpress.com ↗)

1 points · by opensas · 14y ago · discuss

13.

Deploying Play Framework 2 apps, with Java AND Scala, to Openshift(playlatam.wordpress.com ↗)

1 points · by opensas · 14y ago · discuss

14.

Supporting Play Framework on OpenShift with the DIY Application Type(redhat.com ↗)

1 points · by opensas · 14y ago · discuss

15.

Playing (2.0) with Twitter Bootstrap, WebSockets, Akka and OpenLayers(dzone.com ↗)

2 points · by opensas · 14y ago · discuss

16.

Play framework 2 tip: interactively play with your app from the scala console(playlatam.wordpress.com ↗)

1 points · by opensas · 14y ago · discuss

17.

First Play framework hackaton in Argentina(playlatam.wordpress.com ↗)

1 points · by opensas · 14y ago · discuss

comment 14y ago · link · parent

and a shiny new play framework site http://www.playframework.org/

19.

Podcast en Java Hispano: Introducción a Play Framework(playlatam.wordpress.com ↗)

1 points · by opensas · 14y ago · discuss

20.

Secure JSON Services with Play Scala and SecureSocial(playlatam.wordpress.com ↗)

2 points · by opensas · 14y ago · discuss

21.

Vote for play framework native support on openshift(redhat.com ↗)

2 points · by opensas · 14y ago · discuss

22.

Spanish translation of Play framework documentation is ready(playlatam.wordpress.com ↗)

1 points · by opensas · 14y ago · discuss

comment 14y ago · link · parent

here's another interesting link http://www.dzone.com/links/dependency_injection_with_play_fr...

24.

Playframework + Google Guice(playlatam.wordpress.com ↗)

12 points · by opensas · 14y ago · 1 comment

comment 14y ago · link · parent

nothing - http://playlatam.wordpress.com/2012/01/13/first-steps-with-s...

comment 14y ago · link · parent

I've found out that with the -savecompiled option the delay is not so pitiful... see http://playlatam.wordpress.com/2012/01/13/first-steps-with-s...

comment 14y ago · link · parent

Why wouldn't it run on any unix, linux, or windows, or wherever a JVM can run? you should run it with "scala status.scala"

apart from that, I came to a similar conclusion: http://playlatam.wordpress.com/2012/01/13/first-steps-with-s...

comment 14y ago · link · parent

yeap, python is pretty cool, see http://playlatam.wordpress.com/2012/01/13/first-steps-with-s...

comment 14y ago · link · parent

thanks for the tip, here's my bash version http://playlatam.wordpress.com/2012/01/13/first-steps-with-s...

comment 14y ago · link · parent

Thanks to everybody's feedback on this one... You encouraged me to write another article, mainly because I felt a little guilty for bashing (pun intented) bash and python ;-) Hope you like it http://playlatam.wordpress.com/2012/01/13/first-steps-with-s...
12