Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use Reactive Extensions in a MonoTouch project?

There is a port of Rx called mono-reactive that contains a MonoTouch project but the author announced ten days ago he is abandoning the project in favor of Microsoft open source implementation:

I happily announce that I'm not going to work on this code base anymore now that Microsoft has open-sourced Reactive Extensions in Apache license. http://rx.codeplex.com/

MonoDevelop hangs trying to open Rx.sln in Rx master and there isn't a MonoTouch target there anyway. PCL support is not there yet for MonoTouch too.

I'm wondering if anyone already put up a MonoTouch-compatible project for Rx and whether it is actually usable in production.

like image 223
Dan Abramov Avatar asked Nov 19 '12 21:11

Dan Abramov


1 Answers

Microsoft Rx

I put up a project myself, combining Core, Interfaces, Linq and PlatformServices from Rx's codeplex.
There you go:

https://github.com/stampsy/rx-monotouch

It works fine with reference types, much less so with value types (see below).
Unfortunately it doesn't compile due to bug 8329 and 9087. It compiles just fine now.

mono-reactive

I also used mono-reactive and it worked pretty well for me. While Microsoft's implementation seems more concise and reliable, mono-reactive is smaller and easier to fix when really needed.

You can try both and see what works best for you.
Happy observing!

Mitigating Crashes

With both frameworks I often ran into crashes caused by AOT limitations on the device. I was told by Rolf of Xamarin that you can often work around most AOT limitations by not using value types as Rx generic type parameters.

For example, IObservable<bool> extensions will probably crash on the device, and so will IObservable<long>, but reference types should work fine with most methods.

In my version of Rx I added IntervalSafe method that returns Unit (which I changed to be a reference type, rather than a struct) instead of long, and thus doesn't cause tens of crashes all over the codebase.

Some Rx methods still crash, but it's fairly easy to fix these crashes.

See Throttle fix by Costo or my Buffer fix for reference.
I will happily merge pull requests that address other Rx methods and their overloads.

like image 74
Dan Abramov Avatar answered Nov 13 '22 04:11

Dan Abramov