Live data from Hacker News

Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

yz.mit.edu

11–20 of 31 posts

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#11
post #5

Interesting project. I'm uneasy about zero HTML, and instead having most/all the HTML in .coffee. But I'm opened to it. Is this project related to, or draw inspiration from, Reactive Extensions (Rx.NET, Rx.js, Rx.cocoa, etc.)? https://github.com/Reactive-Extensions/RxJS Recently, I've seen the idea of reactive user interface pop up all over HackerNews and GitHub. What a lot of folks are missing is that whole applicat…

If you want a better alternative to RxJs, also written in Coffescript, check out Bacon.js.

https://github.com/raimohanska/bacon.js

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#12
post #10
post #7

Earlier quoted context omitted.

We elaborate briefly on various related work at http://yang.github.io/reactive-coffee/related.html , but absolutely - there's a large body of existing work and trailblazers we liberally draw inspiration from. In the case of RxJS in particular, the styles actually feel quite different - RxJS is more about explicitly merging streams and constructing the data flow graph with some set of combinators, whereas dependencies…

Facebook's recent React framework is also worth mentioning ( http://facebook.github.io/react/ ). A nice JS library for reactive programming is Bacon.js - https://github.com/raimohanska/bacon.js - it's smaller, the source code is easier to read and I found it a little easier to use.

Indeed, both are mentioned in the related work page!

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#13
"z = bind -> x.get() + y.get()" seems nice, but when are the attached listeners removed again?

Typically this is solved with weak listeners, but Javascript doesn't support weak references. I'm worried that this library never removes the listeners, effectively leaking like crazy?

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#14
I really like this. As an avid user of Coffeescript, Knockout.js and Erector-style code-as-templates, this is a great fit for me. Additionally, while I now understand how Knockout works internally, I was initially frustrated by how much magic it involved; Reactive.coffee looks like it does a better job of exposing the relevant parts of how it works.

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#15

"z = bind -> x.get() + y.get()" seems nice, but when are the attached listeners removed again? Typically this is solved with weak listeners, but Javascript doesn't support weak references. I'm worried that this library never removes the listeners, effectively leaking like crazy?

Astute observation - this is actually something we do call out in http://yang.github.io/reactive-coffee/infelicities.html#garb.... As you note, JS doesn't have it as easy as in other platforms, but it's not a fundamental problem and is still reasonably straightforward to address (as described). The fix is slated for this coming release, and we'll need to more thoroughly document/explain what this all means.

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#16
Do you feel that you've lost anything in terms of composeability as compared to a more stream/combinator-oriented approach, like, say, Flapjax? If so, have you found that painful in the real world, or do you think it's more of an academic concern with little meaningful impact?

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#17
post #15

"z = bind -> x.get() + y.get()" seems nice, but when are the attached listeners removed again? Typically this is solved with weak listeners, but Javascript doesn't support weak references. I'm worried that this library never removes the listeners, effectively leaking like crazy?

Astute observation - this is actually something we do call out in http://yang.github.io/reactive-coffee/infelicities.html#garb... . As you note, JS doesn't have it as easy as in other platforms, but it's not a fundamental problem and is still reasonably straightforward to address (as described). The fix is slated for this coming release, and we'll need to more thoroughly document/explain what this all means.

Thanks for the explanation in the link. The problem that is described in the link is clearly solvable, however what I'm referring to is more fundamental.

I'm not talking about nested binds, but just a simple bind such as "z = bind -> x.get() + y.get()". This will add listeners to x and y. When will those listeners be removed again (without adding new ones during the recalculation of z's new value in case of a change to x or y)?

It may be that x and y are the basic models in my app, and during my clicking around in the application I create and close many panels, and each panel has bind-operations that add listeners to x and y. Now the panels may be long gone, and will never be used again, but when will the listeners that was added to x and y as part of creating the panels be removed?

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#18
post #15

Earlier quoted context omitted.

Astute observation - this is actually something we do call out in http://yang.github.io/reactive-coffee/infelicities.html#garb... . As you note, JS doesn't have it as easy as in other platforms, but it's not a fundamental problem and is still reasonably straightforward to address (as described). The fix is slated for this coming release, and we'll need to more thoroughly document/explain what this all means.

Thanks for the explanation in the link. The problem that is described in the link is clearly solvable, however what I'm referring to is more fundamental. I'm not talking about nested binds, but just a simple bind such as "z = bind -> x.get() + y.get()". This will add listeners to x and y. When will those listeners be removed again (without adding new ones during the recalculation of z's new value in case of a change…

Yeah, this is what I'm talking about - a fuller explanation would require more text. :)

The question is what you're doing with z. As long as you're also adding and removing your hypothetical panels in turn with bind, you're good:

  div {class: 'container'}, bind -> [
    if show.get()
      div {class: 'z'}, bind -> x.get() + y.get()
    else
      div {class: 'nothing'}
  ]
The question is what happens at the top level or when you want to break out and do your own thing. We don't have the luxury of weak refs in JS, and as a result it's less forgiving if you do "silly" things like create binds that go nowhere and that you don't want to keep. But even with weak references, one can't tell if you added a bind only to subscribe a console.log caller to its changes, save to localStorage, or some other side effect that you do want to keep. In any case, it's incumbent on us to fully document what "silly" means, include simple-to-use API calls to capture and dispose entire subgraphs (for when you want to do your own thing manually), and provide good debugging introspection tools for finding these `bind`s to nowhere, in case you really don't want them lingering around.

We've also been bouncing around ideas for reversing the reference DAG and having cells named by the reversed paths through the DAG, which we may experiment with. You then get to deal with the converse problem of manually needing to hold references to the sinks in the DAG. In any case, we're very open to learning from how things play out in practice, and shape the direction of the library accordingly.

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#19

Do you feel that you've lost anything in terms of composeability as compared to a more stream/combinator-oriented approach, like, say, Flapjax? If so, have you found that painful in the real world, or do you think it's more of an academic concern with little meaningful impact?

Good question - the reason why we built the library this way was exactly because we find declaring expressions to be more natural than wiring together streams by combinators—which, BTW, Flapjax does support. Far from academic-without-impact, Leo's work was actually directly influential on me—esp. since he worked in PL and I didn't, so much of my initial exposure to reactive programming came from a few projects including his.

Re: Reactive.coffee: reactive programming and declarative UIs in CoffeeScript

#20
This is a really nice cleanup/update on Knockout. The source code at ~400 lines is very understandable. I've looked at a lot of reactive frameworks, this is great work!

I'm glad you're thinking about how to manage garbage collection. It's tricky with these push-based frameworks.

Have you given consideration to asynchronous vs synchronous reactivity? The advantage of asynchronous is you don't propagate the changes as they are made but instead once all the changes are done. You can avoid redundant computations this way, for example if a bind is dependent on multiple observables that change in the same "turn". And in some ways (worth debating) asynchronous semantics are more understandable than synchronous since unknown code is not being run underneath you while you are in the middle of changing observables.

Here's Ember's writeup on their rationale for asynchronous: http://emberjs.com/guides/understanding-ember/managing-async...

Also since Object.observe is asynchronous, Google's polymer/MDV will also I believe have these semantics.

Post reply on HN