java - Most effective way to turn Observable into ObservableValue/Binding/EventStream? -
i using rxjava , reactfx more heavily, trying understand how reconcile 2 since reactfx not have rxjava dependency, how can 2 talk each other within same monad? case bridging between javafx's observablevalue, rxjava's observable, , reactfx's streamevent without lot of boilerplate.
i want compose core business logic rxjava since won't backing javafx applications. want javafx ui use reactfx , utilize eventstream. question effective way turn eventstream observable, , observable eventstream, binding, or observablevalue? know use rxjava across board want leverage reactfx's platform thread safety , conveniences...
//desire 1- turn eventstream observable in same monad observable<foo> obs = eventstream.valuesof(fooobservablevalue).toobservable(); //desire 2- turn observable observablevalue, eventstream, or binding binding<foo> obsval = observable.create(...).tobinding();
to turn reactfx eventstream rxjava observable:
observable<foo> torx(eventstream<foo> es) { publishsubject<foo> sub = publishsubject.create(); es.subscribe(sub::onnext); return sub; } to turn rxjava observable reactfx eventstream:
eventstream<foo> fromrx(observable<foo> obs) { eventsource<foo> es = new eventsource<>(); obs.subscribe(foo -> platform.runlater(() -> es.push(foo))); return es; } notice platform.runlater(...) in latter case. makes resulting eventstream emit events on javafx application thread.
also note ignoring subscriptions returned subscribe methods in both cases. fine if establishing binding lifetime of application. if, on other hand, binding between them should short-lived, in first case, have rxjava component expose subject, reactfx component expose eventstream, , subscribe/unsubscribe necessary. second case.
Comments
Post a Comment