You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to map a collection of events (from a datastore) to a list of choices (in a different datastore) made by a user for some / all of the events in that collection.
The collection of events is stored in a LoadingProperty. Something like :
public let events: LoadingProperty<[Event], ApplicationError>
....
events = LoadingProperty {
// some HTTP request that retrieves an array of events from a remote server
...
.toLoadingSignal()
}
I will display those events in a UITableView with custom cells that show whether or not the user will attend.
In order to provide a mutable observable array to bind that table to, I have to issue a request for every event to check if the user has already made some selection -- I know, not the best solution, but that's what I am dealing with for now.
So I am building that MutableObservableArray from the events property. Everytime it gets refreshed, then the mapping is established again and the table is updated accordingly :
public let eventsArray: MutableObservableArray<MappingScheduleChoice> = MutableObservableArray([])
...
events
.dematerializeLoadingState()
.suppressError(logging: true)
.with(latestFrom: userService.currentUser.value())
.map { (arg) -> [(Event, User)] in
let (evts, user) = arg
return evts.map { ($0, user) }
}
.unwrap()
.flatMap(.concat) { arg -> Signal<MappingScheduleChoice, ApplicationError> in
let (evt, user) = arg
return evt
.getEventSelection(for: user.localId)
.response(using: client)
.map { $0.first }
.map { MappingScheduleChoice(schedule: evt, choice: $0) }
}
.collect()
.observeNext { state in
self.eventsArray.replace(with: state)
}.dispose(in: bag)
Problem
The main issue is that dematerializeLoadingState() never really completes (just reloads) and therefore collect() can never issue a new array via .next() that would be used to build the MutableObservableArray.
If I add .take(first: 4) right before collect() then the first 4 events will show up in the table with the proper user choices (as intended, but just for those 4 events). I'd like to achieve this for all the events present in the events property.
Now this seems like a very, very complicated solution and I am happy to hear other suggestions on how to achieve the intended result. But, otherwise, any nifty little trick I have forgotten about that could make this work ?
thanks,
N.
The text was updated successfully, but these errors were encountered:
Following up on this as I have another use case, for collect(), which faces the same problem.
For each new carpool (given by the carpoolSignal) I fetch its participants (a property of the carpool storing a dictionary), flatten the elements of the signal into signals of element on which I perform a few operations (filter, flatmap, etc.) and then bind the result to a mutable observable array (riderArray).
However, since carpoolSignal will only send a termination event way after we need to collect the participants for a given carpool, riderArray will always be empty (waiting on "originating" signal to terminate).
So is there a way to use flattenElements() and collect() in a way that will keep the original signal alive (i.e. not using prefix / take) while still emitting a signal of rider arrays ? Or do I need to find a different way to handle a signal of collections.
Description
I am trying to map a collection of events (from a datastore) to a list of choices (in a different datastore) made by a user for some / all of the events in that collection.
The collection of events is stored in a LoadingProperty. Something like :
I will display those events in a UITableView with custom cells that show whether or not the user will attend.
In order to provide a mutable observable array to bind that table to, I have to issue a request for every event to check if the user has already made some selection -- I know, not the best solution, but that's what I am dealing with for now.
So I am building that MutableObservableArray from the
events
property. Everytime it gets refreshed, then the mapping is established again and the table is updated accordingly :Problem
The main issue is that
dematerializeLoadingState()
never really completes (just reloads) and thereforecollect()
can never issue a new array via.next()
that would be used to build the MutableObservableArray.If I add
.take(first: 4)
right beforecollect()
then the first 4 events will show up in the table with the proper user choices (as intended, but just for those 4 events). I'd like to achieve this for all the events present in theevents
property.Now this seems like a very, very complicated solution and I am happy to hear other suggestions on how to achieve the intended result. But, otherwise, any nifty little trick I have forgotten about that could make this work ?
thanks,
N.
The text was updated successfully, but these errors were encountered: