24 comments

[ 3.5 ms ] story [ 63.0 ms ] thread
This is neat. I did something similar to this a while ago for WPF databinding and calculated properties in business objects. Does it support INotifyPropertyChanged?

One of the problems I found is that a lot of team members don't really like to think on that level of abstraction. So it was hard to introduce it team wide and have people keep using it.

Thanks. Yes you can use it to help with INotifyPropertyChanged. The example 'SmartNotifyPropertyChanged' demonstrates one way to do this.
This looks similar to how Meteor's ReactiveVar package, and lower-level Tracker library, works: https://docs.meteor.com/api/reactive-var.html

It's certainly helped make building real-time user interfaces that update when the data changes significantly easier in my opinion, because you're able to express your intent in code more closely to what you mean rather than having to write all the connecting reactive boilerplate yourself.

Yes Meteor's reactive system seems to be almost identical. Thanks for sharing.
Does anyone know if you can do this in reactjs? It would be awesome to build a excel like spreadsheet with user-input formulas.
Wouldn't it be backwards to do this in React? Everything is controlled by a state object you manually set, so you already know when values are going to change.
actually - I'm talking about a function expression. Think about a spreadsheet with a formula similar to "=SUM(A1+B1)". What this means is that when A1 or B1 change.. then this formula result should get re-computed. Remember that A1 and B1 themselves may be computed results...

what happens today is that I need to recompute ALL formulas - because there is no easy way to know which formulas changed.

(comment deleted)
Why use this instead of or with Rx.NET?
There are also Continuous LINQ [1][2], Bindable LINQ [3], Obtics [4] and OLinq [5], some predating Rx [6][7]. Besides OLinq they all seem no longer maintained but in case somebody is interested in other existing implementations, there you go. Also note that they don't all solve the exact same but similar problems.

[1] http://clinq.codeplex.com [2] https://github.com/ismell/Continuous-LINQ [3] https://bindablelinq.codeplex.com [4] http://obtics.codeplex.com [5] https://github.com/wasabii/OLinq [6] https://msdn.microsoft.com/en-us/data/gg577609.aspx [7] https://github.com/Reactive-Extensions/Rx.NET

Rx.net is probably the most well used one.
There are many application-specific scenarios that are enabled by RX that would still take quite a bit of hand-rolling a deep knowledge of RX to get right.

A favorite of mine right now is https://github.com/RolandPheasant/DynamicData which I use for easily "deriving" from in-memory collections to create new collections that are actually "live views" onto the source collection. Makes things like mapping, sorting, filtering, paging, and so on super-simple while letting you avoid creating unnecessary state.

I like componentized functionalities a lot, and i think .NET shines for that.
This is not a replacement for Rx, actually it relies on Rx. SmartReactives is an addition to Rx which allows you to get an IObservable from an expression for free, while with just Rx you'd have to instrument your expression.
If you're using JavaScript, MobX [1] is a library available that implements this pattern, which I find a bit easier to use than Meteor's Tracker yet also comes with super-performant React bindings.

[1] https://github.com/mobxjs/mobx

I wonder how does this compare to Jane's Street Incremental library?
My perception is that there's almost no overlap in scope between the two libraries. In Incremental you have to be explicit about which variables your computations depends on, while SmartReactives' sole purpose is discovering these dependencies automatically. SmartReactives discovers dependencies as a side-effect of evaluating variables while evaluating expressions. OCaml on the other hand is a mostly pure language so side-effects are not allowed.

Incremental on the other hand does cool stuff like use the result of the first computation to make the second computation faster, which SmartReactives does not do at all.

So I'd say although the projects are related they don't overlap in scope.

I wrote something that does this too! I'm looking forward to seeing the differences in our implementations :D
Alright. Where can I find your project? You can let me know in Gitter or e-mail.