R3
R3 is an open source implementation of the ReactiveX 🔗 API.
It is located on github 🔗 where it delivers a documentation of how to install it into Unity but if you follow the Quickstart instructions then you do not have to install it, and it will already be present.
git-amend has done an introductory video on R3 on Youtube 🔗. It is rather a showcase than an explanation.
Inside TBE, R3 is used in many places. If you haven’t made yourself familiar with reactive programming, you can think of it as data-binding which in turn means the effort to automatically update model and view (UI) when a model value changes (without having to query the model every frame or on certain events).
Reactive Programming can be difficult to get a grip on and I also plan to explain its usage in TBE in more detail.
Reactive Programming
Publish Subscribe
One fundamental of reactive programming is the publish-subscribe mechanism.
Notice how this simple diagram implies:
-
The Subscriber depends on the Publisher.
-
This is the same as saying: The Subscriber knows the Publisher.
-
-
Now if the Publisher would also know his Subscriber(s) then we would have introduced a cyclical dependency and that is very bad, we never want a cyclical dependency.
-
Therefore, the Publisher MUST NOT know its Subscriber(s).
-
But he must be able to notify them. How can this be done? The solution is called dependency indirection. Instead of keeping a list of subscribers, the publisher keeps a list of subscriptions. So the act of subscribing can be visualized like this:
-
This has the bonus advantage that the subscriber can cancel the Subscription.
Reactive
in Reactive and R3, the publisher is also sometimes called:
-
Observable (R3 defines
R3.Observable<T>where T is the type of the emitted values) -
Observable Sequence (Reactive)
-
Subject
in R3 the Subscription is of type System.IDisposable and calling its Dispose() method cancels the subscription.