swift - RxSwift: Zip Observables only if requirements are met -


imagine user profile allows editing of fields name, surname, age , avatarimage. when user clicks save, requests sent each value has been changed.

now please think of functions signatures those:

func rx_updateusername(name: string) -> observable<updateusernameresponse> func rx_updatesurname(surname: string) -> observable<updatesurnameresponse> func rx_updateage(age: int) -> observable<updateageresponse> 

normally zip requests this:

let namereqobservable = rx_updateusername("gandalf") let surnamereqobservable = rx_updatesurname("the white") let agereqobservable = rx_updateage(123)  let zippedrequests = observable.zip(namereqobservable, surnamereqobservable, agereqobservable,      resultselector: { (usernameresponse, surnameresponse, areresponse) in      return (usernameresponse, surnameresponse, areresponse) }).subscribenext(...) 

what should when want perform requests values changed?

have tried .combinelatest()? visualization here - http://rxmarbles.com/#combinelatest in case, whenever there value changed in 1 of input observables, combinedrequests observable emit new set of inputs.

let combinedrequests = observable.combinelatest(namereqobservable, surnamereqobservable, agereqobservable,      resultselector: { (usernameresponse, surnameresponse, ageresponse) in      return (usernameresponse, surnameresponse, ageresponse) }).subscribenext(...) 

doc rxswift, .combinelatest():

merges specified observable sequences 1 observable sequence using selector function whenever of observable sequences produces element.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -