Introduce AnonymousSubject
RxLua only has a zero-version create() function for Subject, corresponding to the constructor of RxJS for example. However, RxJS and other ReactiveX implementations also have a two-argument create() function, returning a subject that simply juxtaposes an observable and an observer into a single object. Quite confusingly, the object returned by create() is not a Subject, but an instance of a different class AnonymousSubject. This pull request introduces AnonymousSubject as a completely separate implementation to avoid overloading Subject.create.
Hi, could you please take a look at this?
Personally I'm wondering what's the use case for that? I know the AnonymousSubject class but I've never seen it actually used anywhere in the real code outside of the RxJS internals. Can you provide some examples when is it useful to have something like that?
You can use AnonymousSubject to define an operator that returns a hot observable. Usually the Observable will be a Subject too, for example a BehaviorSubject.
On the Observer side, the onNext method will "do something" with the value it receives and push to the destination Subject. For example the observer could accept a boolean value for "is the network connection available", try connecting to a server when the network connection becomes available, and push true to a BehaviorSubject if the attempt to connect succeeds. This AnonymousSubject would tell you upon subscription whether you are connected to the server.
Thanks for the explanation.
I'm maintaining a fork of this library which I called Lua-ReactiveX and I've also included AnonymousSubject there in order to implement proper automatic unsubscription, but it works a little bit differently (because one of the create() parameters is required to be a factory function).
I'm considering however to rename it to something else like ProxySubject and leave it private behind the scenes, and then an actual public implementation of AnonoymousSubject like the one you're offering here could be added there. Would you be interested in preparing a pull request for that in my fork? The fork is going to be actively maintained by me, because I'm actually using it myself and need it to be stable and possibly bug-less :)
Not sure when but yeah, I can contribute with a pull request.