Zelkova: Elm-style FRP for Clojure and ClojureScript

450 views
Skip to first unread message

James MacAulay

unread,
Oct 19, 2014, 8:51:08 PM10/19/14
to clojur...@googlegroups.com
I've just published an FRP library based on Elm[1]:

https://github.com/jamesmacaulay/zelkova

Here's what the app code looks like:

https://github.com/jamesmacaulay/zelkova/blob/4b06c49678e11e3af7b1eda7a18929a512f7753d/examples/mario/src/mario/core.cljs#L118-L133

Right now Zelkova includes ports of Elm's Signal, Mouse, Keyboard, and Window libraries, plus part of its Time library[2]. Zelkova's signal namespace works in both Clojure and ClojureScript, but the rest only have implementations for ClojureScript in the browser.

Elm-style FRP is a bit different from other flavours like those of Rx or Bacon.js. In particular, Elm's signal graphs are static (can't be reconfigured once they start running) and don't allow for signals-of-signals.

Zelkova is the same way, but its signal functions actually return "recipes" for signals which don't start processing values until a "live" graph gets spawned from one of them. This allows multiple live graphs to run concurrently while sharing logical structure, and should make some things easier in the future (like porting Elm's time-travelling debugger). Theoretically this should also make it possible to compile some kinds of signal graphs into transducers instead of running them as networks of core.async channels.

If you're interested in the differences and tradeoffs between the different forms of FRP out there, Evan Czaplicki gave an excellent talk on the subject at Strange Loop this year:

https://www.youtube.com/watch?v=Agu6jipKfYw

Cheers,
James

[1] http://elm-lang.org
[2] https://github.com/jamesmacaulay/zelkova/tree/master/src/cljx/jamesmacaulay/zelkova

Reply all
Reply to author
Forward
0 new messages