java - RxJava- CombineLatest but only fire for one Observable's emission? -
let's have 2 infinite observables can emit values @ moment. combine create observable<processfileevent>.
observable<integer> selectedfileid= ... observable<mouseclick> buttonclick = ... observable<processfileevent> `processfileevent` = observable.combinelatest(selectedfileid, buttonclick, (s,b) -> { //create processfileevent here }); the problem want processfileevent emit when buttonclick emits something, not selectedfileid. it's not behavior user expects when file id inputted , kicks off processfileevent. how combine emit when buttonclick emits?
use .distinctuntilchanged() on mouseclick object. way you'll events when mouseclick changes.
create class contains both fileid , mouseclick:
static class filemouseclick { final int fileid; final mouseclick mouseclick; filemouseclick(int fileid, mouseclick mouseclick) { this.fileid = fileid; this.mouseclick = mouseclick; } } then
observable.combinelatest(selectedfileid, buttonclick, (s,b) -> new filemouseclick(s,b)) .distinctuntilchanged(f -> f.mouseclick) .map(toprocessfileevent())
Comments
Post a Comment