import rx.Observable; | |
import rx.subjects.PublishSubject; | |
public class Property<T> { | |
private T value; | |
private PublishSubject<T> property; | |
public Property() { | |
property = PublishSubject.create(); | |
} | |
public T getValue() { | |
return value; | |
} | |
public void setValue(T value) { | |
this.value = value; | |
property.onNext(value); | |
} | |
public Observable<T> observe() { | |
return property.asObservable(); | |
} | |
} |
import rx.Observable; | |
public class PropertySample { | |
public static void main(String[] args) { | |
Property<String> property = new Property<>(); | |
property.observe().subscribe(System.out::println); | |
property.setValue("New Value from Setter"); | |
Observable.just("New Value from Observable") | |
.subscribe(property::setValue); | |
System.out.println("Current val=" + property.getValue()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment