GenieFramework / GenieBuilder.jl

Other
16 stars 1 forks source link

Variables in a triggered reactive handler are reset to their initial value #64

Open PGimenez opened 5 months ago

PGimenez commented 5 months ago

The issue is that when a handler is triggered, only the variable attached to the handler has its value updated - all others are reset to the initial values. This only happens in GB, if you run the app from the REPL with Genie.loadapp() it works fine.

Here's a video describing the issue: https://www.dropbox.com/t/9lPvnBmjVURgbQ9m

and the code to reproduce it:

using GenieFramework
@genietools

@app begin
    @out vowels=["a","b","c","d"]
    @in selected_vowels = ["a", "b"]
    @in N = 1.0
    @in trigger = false

    @onchange trigger begin
        println("Trigger clicked")
        @show selected_vowels
        @show N
    end

    @onchange selected_vowels begin
        println("Vowel selected")
        @show selected_vowels
        @show N
    end

    @onchange N begin
        println("Number picked")
        @show selected_vowels
        @show N
    end
end

ui() = [p("{{selected_vowels}}, {{N}}"),select(:selected_vowels, options=:vowels, var":multiple"="true"), slider(1:1:10,:N), btn("Trigger", @click("trigger = !trigger"))]
@page("/",ui)
essenciary commented 5 months ago

Updated codebase:

using GenieFramework
@genietools

@app begin
    @out vowels=["a","b","c","d"]
    @in selected_vowels = ["a", "b"]
    @in N = 1
    @in trigger = false
    @out message = "Hello, World!"

    @onchange trigger begin
        println("Trigger clicked")
        # selected_vowels = selected_vowels
        # N = N
        message = "Button clicked. N = $N, selected vowels = $selected_vowels"
    end

    @onchange selected_vowels begin
        println("Vowel selected")
        # selected_vowels = selected_vowels
        # N = N
        message = "Vowel selected. N = $N, selected vowels = $selected_vowels"
    end

    @onchange N begin
        println("Number picked")
        # selected_vowels = selected_vowels
        # N = N
        message = "Number picked. N = $N, selected vowels = $selected_vowels"
    end
end

ui() = [
  p("{{selected_vowels}}, {{N}}")
  p("{{message}}")
  select(:selected_vowels, options=:vowels, var":multiple"="true")
  slider(1:1:10,:N)
  btn("Trigger", @click("trigger = !trigger"))
]

@page("/", ui)
essenciary commented 5 months ago

This is now fixed but with more of a hack fix in GenieBuilder. The actual problem seems to have been introduced in Stipple 0.28 but will require more time to debug.