Mirrored observable collections

Tomas Mikula tomas.mikula at gmail.com
Wed Jul 23 12:47:56 UTC 2014


On Wed, Jul 23, 2014 at 1:16 PM, Mike Hearn <mike at plan99.net> wrote:
> Thanks Tomas! I'm a big fan of your work and blog.
>
> I learned about ReactFX after I started writing my current project, seems
> like a very useful abstraction indeed, although so far I've found the basic
> JFX stuff to be nearly sufficient (a few more transformers and mirrored
> observables were so far all I needed).
>
> Actually I didn't realise ReactFX could do this. I learned about what it can
> do by reading the github page which covers many features but doesn't mention
> threading anywhere, so I figured it didn't have any support for it. I should
> have dug deeper! Maybe you could add a discussion of threading and how to
> manage asynchronous state using ReactFX?

Yeah, this information is missing on the project site.

> Additionally a discussion of debugging would be helpful. My experience so
> far is that reactive/streaming code is fun to write and painful to debug
> compared to traditional imperative code.

In a debugger, yes. On the other hand, I find it easy to write tests for.

>
> In my UI I use content bindings, so I'd need to (I think) use
> EventStreams.merge() to merge the event stream back into a copy of the set,
> and at that point the API would be more verbose than
> MirroredObservableSet/List. Still ReactFX is clearly a lot more general and
> I might well switch to it at some point.

My suggestion was for the case "if you only care about changes and not
full content". If you want the full collection on both sides, then
your mirrored collections make sense. You could still use the
mentioned threadBridge method to transfer change events, but that's
just a minor part of the implementation.

>
> Incidentally the lack of a uni-directional string binding utility in JavaFX
> is really annoying: converting a read only observable value into a string is
> a really common thing to want to do!

You can use EasyBind:

    ObservableValue<T> src = ...;
    ObservableValue<String> str = EasyBind.map(src, t -> format(t));

although it's not as concise and fluent as

    ObservableValue<T> src = ...;
    ObservableValue<String> str = src.map(t -> format(t));

would be.


More information about the openjfx-dev mailing list