Trying to use System.Reactive or looking for another Reactive implementation

Started by Homez, March 20, 2020, 11:41:53 PM

Previous topic - Next topic

Homez

Tried to include System.Reactive but discovered it isn't compatible with Mono. Does anyone here use any good Reactive implementations? I've heard of UniRx and will be giving it a shot, but if you have thoughts, suggestions, warnings, threats, or experience I'd love to hear them.

Homez

UniRx works beautifully, though it's a pain to acquire since it's only available on the Unity Assets Store (it is free, though).

Now I can do fun stuff like this:

private IObservable<bool> RowsBecameValidFactory()
        {
            bool lastValidityState = false; // can start false because after a new row is added, it will always be invalid

            // observable that emits when the list's rows go from "not all being valid" to "all being valid"
            return rows.ToObservable()
                .SelectMany(u => u.RowBecameValid)
                .Select(u => rows.All(v => v.IsValid()))
                .Where(curValidityState =>
                {
                    bool validityStateChanged = curValidityState != lastValidityState;
                    lastValidityState = curValidityState;
                    return validityStateChanged && curValidityState;
                }
            );
        }


I'm working on a GUI dialog box that contains a list component which in turn contains row components. Each row has a "RowBecameValid" Observable that fires whenever the row goes from invalid to valid. The above snippet is taking all those "RowBecameValid" Observables and combining them into an "AllRowsBecameValid" Observable that my list component can use. So now instead of having to poll to see if my rows became valid, or rolling out my own callback/event management code (ughh...), I can just use UniRx! Yay.