Created
February 10, 2014 13:28
-
-
Save jemgold/8915937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)thing | |
{ | |
// So I have two signals… | |
RACSignal *addedSignal = [[NSNotificationCenter defaultCenter] rac_addObserverForName:@"added" object:nil]; | |
RACSignal *removedSignal = [[NSNotificationCenter defaultCenter] rac_addObserverForName:@"removed" object:nil]; | |
// This doesn't get called until removedSignal gets it's first thingy. | |
[[RACSignal combineLatest:@[addedSignal, removedSignal]] subscribeNext:^(id x) { | |
// TODO could this binding be better? | |
[self.data replaceObjectAtIndex:0 withObject:self.meteorClient.collections[@"posts"]]; | |
[self.collectionView reloadData]; | |
}]; | |
// addedSignal always gets called immediately so this works | |
[[RACSignal combineLatest:@[addedSignal]] subscribeNext:^(id x) { | |
// TODO could this binding be better? | |
[self.data replaceObjectAtIndex:0 withObject:self.meteorClient.collections[@"posts"]]; | |
[self.collectionView reloadData]; | |
}]; | |
// so I can replace it with these two | |
[addedSignal subscribeNext:^(id x) { | |
[self.data replaceObjectAtIndex:0 withObject:self.meteorClient.collections[@"posts"]]; | |
[self.collectionView reloadData]; | |
}]; | |
[removedSignal subscribeNext:^(id x) { | |
[self.data replaceObjectAtIndex:0 withObject:self.meteorClient.collections[@"posts"]]; | |
[self.collectionView reloadData]; | |
}]; | |
// but that sucks. | |
// I know you can use | |
RACAbleWithStart(…); | |
// but I can't figure out how to get a NotificationCenter signal to broadcast an initial value. | |
// or maybe I'm not looking for combineLatest at all? how do I get two signals to merge | |
// even if one hasn't published anything yet? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment