JuliaGizmos / Escher.jl

Composable Web UIs in Julia
https://juliagizmos.github.io/Escher.jl
Other
335 stars 63 forks source link

multiple subscriptions / nested maps #148

Closed StreetLevel closed 8 years ago

StreetLevel commented 8 years ago

Hi Sashi, I have some problems creating some sliders, whose values and ranges depend on each other. I would be very nice if you could help me out. Here is a minimal example:

main(window) =  begin
    push!(window.assets,"widgets")
    s1 = Signal(1)
    map(s1) do n1
        vbox1 = (
            hbox(slider(1:5) >>> s1)
        )
        s2 = Signal(n1)
        vbox2 = map(s2) do n2
            vbox(
                hbox(slider(n1:10) >>> s2),
                hbox("s1 = $n1"),
                hbox("s2 = $n2")
            )
        end
        vbox(
            vbox1,
            vbox2
        ) 
    end
end

The problem is: After i once have changed the first slider, the second slider isn't subscribed to the second signal anymore. Is there a way to make this example work?

Best, Max

shashi commented 8 years ago

s2 here will be replaced with a different signal every time s1 updates causing the output to not update correctly. You should instead move s2 out and map over both s1 and s2.


main(window) =  begin
    push!(window.assets,"widgets")
    s1 = Signal(1)
    s2 = Signal(n1)
    map(s1, s2) do n1
        vbox1 = (
            slider(1:5) >>> s1
        )
        vbox2 =  vbox(
             slider(n1:10) >>> s2),
              "s1 = $n1",
              "s2 = $n2"
         )

        vbox(
            vbox1,
            vbox2
        ) 
    end
end

(edit: removed extraneous hboxes)

StreetLevel commented 8 years ago

Ok, thank you. I was thinking way to complicated. I'm closing this one.