RACCommand Initialization Signal Does Not Hit Executable Characters

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) {
    // The value returned from the signal will be an NSValue
    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.

// Send the values of the posts to the view model
[postsRemainingSignal subscribeNext:^(id x) {
    [self.postQueue.postsRemainingSubject sendNext:x];
}];

// When the load command is executed, update our view accordingly
[self.postQueue.loadPostsCommand.executionSignals subscribeNext:^(RACSignal *loadSignal) {
    [loadSignal subscribeCompleted:^{
        @strongify(self);
        [self.collectionView reloadData];
    }];
}];

:

// Create a subject to send view values to
self.postsRemainingSubject = [RACSubject subject];

// Load more posts when less than 4 posts remain
[self.postsRemainingSubject subscribeNext:^(id x) {
    if ([x integerValue] < 4) {
        [self.loadPostsCommand execute:nil];
    }
}];

, , . , , self.postQueue.loadPostsCommand.executionSignals.

, GitHub - . ?

+4
1

, executionSignals postsRemainingSubject ( -execute:).

executionSignals , postsRemainingSubject, , .

+5

All Articles