I am trying to find best practice for handling multiple subqueries for each value received from a parent query. I am trying to use the same logic as here - Cocoa 5 reaction and ReactiveSwift to handle network requests , but there are some problems.
What we need:
1. TableView with an infinite scroll handler (SVPullToRefresh)
2. Selects a list of objects for each time handler. 3. Send a "subquery" for each object from the response
Notes:
1. All requests (parent + sub-requests) must be canceled after the viewController is closed (deinit called)
2. I need to be able to cancel the parent request at any time. This should also cancel all subpages.
I currently have
I know what I am doing in the "endless handler", it's a kind of sticky tape, but I'm new to ReactiveSwift ...
self.tableView.addInfiniteScrollingWithActionHandler { [unowned self] in
self.tempMutableProperty.value = true
}
self.tempMutableProperty.producer.skipNil().flatMap(.latest) { [unowned self] tempValueThatIDontNeed in
return self.producerForParentRequest(offset: self.offset)
.take(during: self.reactive.lifetime)
.on(
value: { [unowned self] items in
self.items.append(items)
self.tableView.reloadData()
self.offset += items.count
}
).flatMapError { error in
return SignalProducer.empty
}
}.observe(on: UIScheduler().start()
So, as you can see, I have pagination using tableView. I collect a list of objects for each page. Then, for each element from the answer, I need to get additional information with request No. 2.
:
1. , tempMutableProperty - parent request - -
2. sub-request , , , value/error sub-request , , 10 , 10 . , ,
3. , . , , , , parent request sub-requests .
4. # 2, , . , parent request, sub-requests parent request
5.. self.deinit, self.lifetime, ,
, , / self, , sub-request - .