想象一个允许编辑姓名、姓氏、年龄和头像图像等字段的用户配置文件。当用户单击Save
时,会针对已更改的每个值发送请求。
现在请考虑具有以下签名的函数:
func rx_updateUserName(name: String) -> Observable<UpdateUserNameResponse>
func rx_updateSurname(surname: String) -> Observable<UpdateSurnameResponse>
func rx_updateAge(age: Int) -> Observable<UpdateAgeResponse>
通常我们只会zip
像这样的请求:
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(...)
当我只想对已更改的值执行请求时,我应该怎么做?