Given an arbitrary field of a Java object, I want to create an Observable that will observe this field and click a new result on the Observer each time the field value changes. ReactiveCocoa has a RACObserve macro that seems to do just that.
I want to know how to implement similar functionality using RxJava.
For example, let's say I had the following simple class:
public class Foo { enum State { Idle, Ready, Error } private State currentState = State.Idle;
I want to create an Observable<State> that will trigger a new state in Observer every time something changes the value of currentState .
In ReactiveCocoa, it seems I will write something like the following (please excuse my pseudo Objective-C):
[RACObserve(self, currentState) subscribeNext:^(NSString *newState) { NSLog(@"%@", newState); }];
How do I achieve similar functionality in RxJava? I think that I may need to move all changes in currentState to the setter, but it is not clear to me where I should then call Observable.create and how to pass the changes to currentState to Observer.
reactive-programming rx-java system.reactive reactive-cocoa
martiansnoop
source share