I worked on an MVVM example using ReactiveCocoa, which is a simple App.net message collection in the form of a collection that loads more messages before hitting the edge of the collection view.
I have a problem, however, with the team on my view model. I created a team that downloads messages through the AFNetworking client and responds after they have been modeled. When it completes, it sends a response to the signal that the command with which it was created, and completes the signal.
self.loadPostsCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[[EPHTTPClient sharedClient] getGlobalTimelinePostsWithSuccess:^(NSURLSessionDataTask *task, id responseObject) {
[self.posts addObjectsFromArray:responseObject];
[subscriber sendNext:responseObject];
[subscriber sendCompleted];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
[subscriber sendError:error];
}];
return nil;
}];
}];
In my opinion, I am creating a signal to send the remaining number of messages as such.
@weakify(self);
RACSignal *postsRemainingSignal = [[RACObserve(self.collectionView, contentOffset) map:^(id value) {
CGPoint offset = [value CGPointValue];
NSNumber *postsPassed = @(floorf(offset.x/320) + 1);
return @([self.postQueue.posts count] - [postsPassed integerValue]);
}] distinctUntilChanged];
I send these values ββto the subject in my view model.
[postsRemainingSignal subscribeNext:^(id x) {
[self.postQueue.postsRemainingSubject sendNext:x];
}];
[self.postQueue.loadPostsCommand.executionSignals subscribeNext:^(RACSignal *loadSignal) {
[loadSignal subscribeCompleted:^{
@strongify(self);
[self.collectionView reloadData];
}];
}];
:
self.postsRemainingSubject = [RACSubject subject];
[self.postsRemainingSubject subscribeNext:^(id x) {
if ([x integerValue] < 4) {
[self.loadPostsCommand execute:nil];
}
}];
, , . , , self.postQueue.loadPostsCommand.executionSignals.
, GitHub - . ?