Note that there are some explanatory texts on larger screens.

plurals
  1. POHow should FRP work at the top level?
    text
    copied!<p>I have been experimenting with creating a <a href="http://www.github.com/oetzi/echo" rel="nofollow">Functional Reactive Programming framework for Scala</a>. One thing at the moment I am confused about is how current implementations have dealt with representing behaviours at the top level. To explain what I mean I'll give an example. Say I have a JPanel and I want to do this:</p> <pre><code> JPanel panel = new Panel() panel.setBackground(new Behaviour(time =&gt; Color.red)) </code></pre> <p>Although the color is static here we want the panel background to update when the value of the Behaviour updates. The way I have done it so far is to essentially create a discretized Behaviour using Events (accessible via a <code>changes</code> function on Behaviours). This is basically just an event source that occurs whenever the Behaviour changes. Using this the implementation of setBackground here would be:</p> <pre><code>def setBackground(color : Behaviour[Color]) { super.setBackground(color.now) color.changes.each(change =&gt; super.setBackground(change)) } </code></pre> <p>This feels kind of messy. Does anyone have any suggestions of whether this is a bad approach or not? I have been looking at Elliott's <a href="http://conal.net/papers/push-pull-frp/" rel="nofollow">Push-Pull FRP</a> today and it feels like I might be going in the right direction but getting lost somewhere.</p> <p>EDIT: If no one has a definite clear cut solution then ideas/thoughts would be great!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload