Rx-java2 – create custom operators in rxjava2?
It's hard for me to find examples of how to create custom operators using RX Java 2 I have considered several methods:
>Use observable Create, and then flatmapping it from the source observable I can make this work, but it doesn't feel right I finally created a static function. I provided the source observable, and then the flatmap on the source In onsubscribe, then I instantiate an object I pass to the emitter, which handles and manages observable / emitter (because it's not trivial, I want everything to be encapsulated as much as possible). > Create an observable operator and provide it to observable lift. I can't find any examples of rxjava 2 I have to debug my own examples to ensure that my understanding of upstream and downstream is correct Because I can't find any examples or documentation about rxjava 2, I'm a little worried that I might accidentally do something I shouldn't do. > Create my own observable type This seems to be how the underlying operators work, many of which extend abstractobservablewithupstream Although there are many things here, it seems easy to miss something or do something I shouldn't do I'm not sure whether I should take such an approach I gradually completed the psychological process and looked like I would soon become hairy
I'll continue to use the option #2, but I think it's worth asking what methods are supported in rxjava 2, and also find out if there are any documents or examples
Solution
It is not recommended for beginners to write operators, and many required process patterns can be implemented through existing operators
Have you seen rxjava about writing operators for 2 X's wiki? I suggest reading from top to bottom
>It's possible to use create (), but most people use it to emit the elements of a list with a for each loop instead of recognizing that it's flowable Fromiterable do this. > We retain this extension point, although the rxjava 2 operator itself does not use lift() If you want to avoid using the template of option 3, you can try this route. > This is the implementation of the rxjava 2 operator Abstractobservablewithupstream is a small convenience, and external implementers are not required