Question about reactivity and side-effects #2011
-
Hi, I recently came across Pluto and it's reactive updates - it's super cool! I'm trying to understand how the feature works with operations that have side-effects. I'm new to Julia, so I apologize if the answer here lies with Julia and not Pluto. I created a notebook like this: Cell 1: x = Dict("key" => 0) First, I ran cells 1, 2, and 3 and get outputs Dict("key2" => 0), 1, 2 respectively (as expected). Then I changed cell 1 to: x = Dict("key" => 42) and reran it. Cell 3 didn't update. Then I manually re-ran cell 3 and it still didn't update. Removing the assignment in cell 2 and repeating the above steps produces the expected behavior. My question is - what's going on under the hood? Is Pluto caching something? Is the guidance "Reactivity breaks if you do something with side effects - so don't do that."? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey! Take a look at #564 and https://www.youtube.com/watch?v=IAF8DjrQSSk for some background. In your example, Cell 1 is seen as a definition of So when you changed cell 1 to: x = Dict("key" => 42) and reran it, this triggered cell 2 to run (setting the value to |
Beta Was this translation helpful? Give feedback.
Hey! Take a look at #564 and https://www.youtube.com/watch?v=IAF8DjrQSSk for some background.
In your example, Cell 1 is seen as a definition of
x
, and cells 2&3 are referencingx
, and this is all the reactivity information that Pluto has. (Pluto's reactivity is syntax-based, not value-based.) This means that whenever you run cell 1, Pluto will also run cells 2 & 3. Pluto will probably run cell 2 before cell 3, because cell order is used as a tie-breaker in our algorithm.So when you changed cell 1 to: x = Dict("key" => 42) and reran it, this triggered cell 2 to run (setting the value to
1
), and then cell 3, returning2
.