This is a similar question to an earlier question that asked about observing every item in a RACSequence — the correct answer was something like:
RACSignal *valid = [[RACSignal combineLatest:
[self.viewModels map:^id(ViewModel *viewModel) {
return RACObserve(viewModel, state);
}]
]
map:^(RACTuple *states) {
return @([states.rac_sequence all:^BOOL(NSNumber *state) {
return state.unsignedIntegerValue == Completed;
}]);
}
];
My variation on this is that I'd like to also handle the case where ViewModel instances are added/removed from the sequence as well. I can do this by invalidating a RACDisposable stored in an instance variable or property, but it would be great to do this without adding any extra state. What's the right way to do this?
I found the answer in an older post by @justin-spahr-summers: https://stackoverflow.com/a/19711002/63580
Here is the version specific for my question above for posterity: