Hacker News new | past | comments | ask | show | jobs | submit login
Reactive Programming in JavaScript (silk.co)
40 points by salar on March 19, 2014 | hide | past | favorite | 11 comments



Inspired by the client side FRP library we use internally, I've build a small Haskell version as well: https://gist.github.com/sebastiaanvisser/9639321

Although the implementation is different, I tried to keep the interace similar in spirit. Building a Haskell version of a JavaScript library on the side really helps validating your design decisions.


This is excellent - I've been enjoying playing around with ReactiveCocoa recently and it's nice to see how those concepts can work in JS.

Question (and opening a can of worms) - if I'm looking to learn more about FP, should I go for Haskell or Clojure?


As someone who's been going down this rabbit hole for the last year or so:

Haskell is worth learning because a lot of the work done in FRP has been done in a Haskell mindset. Flapjax, Fran, reactive-banana, Elm---all are written in Haskell or trace significant ancestry therefrom.

Clojure is worth learning because, well, it's the future, but also because the community seems to be bent on finding actual application for lofty CS concepts. If you want to use facebook's React, you can use JS, coffescript, facebook's "JSX" compiler, or clojurescript. I'd argue that clojurescript is the most pleasant option.

If you want to learn about FRP inside and out, Haskell. If you want to write something cool and reactive, Clojure.

(Other names to look at if you go clojure: Shafty, Javelin, Lamina, core.asynchronous)


Looks cool but I prefer the syntax of angular's data binding (no need to use #get() or #set()). Is this pretty much the same as angular's data binding?


The ideas here are similar in a sense. I'm not an expert on Angular, but their focus seems to be on templates that update automatically using data bindings. Our framework focuses more on compositionally of reactive data networks, connecting it to the DOM using reactive jQuery methods is just one of the outputs we allow.

The set and get methods are there to go from the JS world to the reactive world and back. Usually you're working with reactive variables (as if they were actual values) directly, in that case you won't use get and set at all.


Ok, I see where there is not getting/setting. Looks very cool.

In angular, there are no setters/getters, you just set values the vanilla way... val = newVal; Angular keeps a reference and a copy of all the watched variables, checks for a change during the 'digest' cycle, and triggers events accordingly. It's not completely for updating the DOM. The syntax for Reactive looks cleaner (I guess ES6 helps a bit).


Not exactly Functional Reactive Programming, FRB (Bindings) are actually a form of Self Adjusting Computation, but similar in spirit to what you see here, and what you see in Angular. You don’t need #get() and #set(), but it’s implemented using ES5 property descriptors and propagates synchronously. Also, unlike dependent properties like Ember, the dependencies do not have to be repeated—they are inferred from the expression language.

https://github.com/montagejs/frb


Awesome! Where is the library? I've been looking on silks github but I must have missed it.


Sadly we haven't open sourced the library (yet?). The actual implementation is quite a bit larger, and messier, than described in this blog post. Additionally, it's written in our own module system. So while we'd like to open source it, it currently is more work than we have time for.


I think I see a typo: 'asVar' should be 'myValue'


Fixed, thanks!




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: