Created
April 29, 2015 13:20
-
-
Save dlew/e40ce3a003e7bc3900df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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