Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should nested map(...) do work? #190

Open
izaid opened this issue Sep 30, 2016 · 4 comments
Open

Should nested map(...) do work? #190

izaid opened this issue Sep 30, 2016 · 4 comments

Comments

@izaid
Copy link
Contributor

izaid commented Sep 30, 2016

Okay, so I have a question about how to modularize signals. Consider the following code:

import Escher

main(window) =  begin
    push!(window.assets,"widgets")
    push!(window.assets, "icons")
    push!(window.assets, "layout2")
    push!(window.assets, "animation")

    sl = Signal(1)
    connected_slider = subscribe(sl, slider(1:10))

    ch = Signal(false)
    connected_checkbox = subscribe(ch, checkbox("Checked?"))

    map(ch, sl) do b, n
        hbox(vbox(connected_checkbox, connected_slider), "Checkbox: $b, Slider: $n")
    end
end

This simply shows the status of a slider and a checkbox, and it works fine. Now what about the following:

import Escher

main(window) =  begin
    push!(window.assets,"widgets")
    push!(window.assets, "icons")
    push!(window.assets, "layout2")
    push!(window.assets, "animation")

    sl = Signal(1)
    connected_slider = subscribe(sl, slider(1:10))

    ch = Signal(false)
    connected_checkbox = subscribe(ch, checkbox("Checked?"))

    map(ch) do b
        map(sl) do n
            hbox(vbox(connected_checkbox, connected_slider), "Checkbox: $b, Slider: $n")
        end
    end
end

I'd imagine this would do the same thing, but instead I get weird effects like duplication of all the widgets. Is this supposed to work? If not, how can I separate the ch and sl signals?

Of course, this is a toy example -- in a real example, I want to do some complicated computation involving the value from one of the signals, or I simply want to modularize one of the signals in a function so that users can call that function but not need to put it in the map.

@izaid
Copy link
Contributor Author

izaid commented Oct 1, 2016

Okay, so my understanding from talking to @shashi is that this should work. I've been debugging it a bit, and the problem seems to lie with this line https://github.com/shashi/Escher.jl/blob/master/src/cli/serve.jl#L119 being used wrongly when there are nested signals -- I can see differences in the diffs there. No fix yet.

@izaid
Copy link
Contributor Author

izaid commented Oct 1, 2016

Partial progress: That line is indeed the problem. It is diffing against Escher.empty at each recursion, whereas it should diff against the last rendering. I've fixed that up with a global dict. This prevents the duplication of widgets, but it leaves the signals not functioning. :/

@shashi
Copy link
Member

shashi commented Oct 8, 2016

I have made the fix where it won't create a new slider. But for some reason, when things get redrawn the watch-states listeners do not get set up. So when the checkbox is checked for the first time, the slider stops working

@izaid
Copy link
Contributor Author

izaid commented Oct 8, 2016

Any idea why that is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants