第6页
func change(productID: ID, count: Int) {
if isChangingProductCount {
return } isChangingProductCount = true Network
.requestChange(productID: ID, count: Int) { result in
result .success { value in Network.requestCart() { result in isChangingProductCount = false result .success { value in
//
} .failure { error in
//
} } } .failure { error in
//
} } }
第7页
var isChangingProductCount: Bool var isFetchingData: Bool
func change(productID: ID, count: Int) {
if isChangingProductCount {
return } isChangingProductCount = true Network.requestChange(productID: ID, count: Int) { result in
isChangingProductCount = false switch result {
// fetchData() // // } } } func fetchData() { if isFetchingData { return } isFetchingData = true Network.requestCart() { result in isFetchingData = false switch result { // //
// // } } }
第11页
changeProductCount
// .flatMap(requestChange)
// .flatMap(requestCart)
// .subscribe { result in
switch result { case .Next(let value): // case .Error(let error): // } }
第16页
func requestCart() {
if isRequesting {
return } isRequesting = true Network
.requestCartInfo() { result in
// Network.requestRecommendPr oducts() { result in
isRequesting = false
// } } }
第19页
Observable .combineLatest(requestCartInfo, requestRecommendProducts) { cartInfoResult, recommendProducts in
//
// ... return newResult } .subscribeNext { value in
//
}
第25页
var isChangingProductCount: Bool var isFetchingData: Bool
func change(productID: ID, count: Int) {
if isChangingProductCount {
return } isChangingProductCount = true Network.requestChange(productID: ID, count: Int) { result in
isChangingProductCount = false switch result {
// fetchData() // // } } } func fetchData() { if isFetchingData { return } isFetchingData = true Network.requestCart() { result in isFetchingData = false switch result { // //
// // } } }
第26页
var isFetchingData: Bool
func fetchData() {
if isFetchingData {
return } isFetchingData = true
// Network.requestCart() { result in
isFetchingData = false // switch result { // //
// // } } }
第29页
[ requestCartInfo.map { _ in true }, response.map { _ in false }
]
.toObservable() .merge()
.subscribeNext { isRefreshing in
// }
第38页
changeProductCount
// .flatMap(requestChange)
// .flatMap(requestCart)
// .subscribe { result in
switch result { case .Next(let value): // case .Error(let error): // } }
第39页
class CartViewModel {
let elements = Observable<[CartProductModel]> /// let deleteResult: Observable<APIResult<Bool>> /// let confirmResult: Observable<CartConfirmResult> /// let isRefreshing = Variable(false)
init(input: ( // refreshTrigger: Observable<Void>, /// loadTrigger: Observable<Void>, /// confirmTrigger: Observable<Void>, /// selectProductsTrigger: Observable<[(subProductID: Int64, selected: Bool)]>, // changeProductCountTrigger: Observable<(subProductID: Int64, count: Int)>, // deleteProductsTrigger: Observable<[Int64]>, )
){…} }