Skip to content

Instantly share code, notes, and snippets.

@bobspryn
Created June 17, 2014 06:44
Show Gist options
  • Save bobspryn/6ffad42a7a44296dd8f8 to your computer and use it in GitHub Desktop.
Save bobspryn/6ffad42a7a44296dd8f8 to your computer and use it in GitHub Desktop.
- (void) viewDidLoad {
[super viewDidLoad];
self.fetchUserMenuDataCommand = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
return [TCAPI fetchUserMenuData];
}];
RAC(self, menuData) = [self.fetchUserMenuDataCommand.executionSignals switchToLatest];
RACSignal *userIsLoggedInSignal = [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:kUserLoggedOutNotification object:nil]
mapReplace:@NO]
startWith: @YES];
@weakify(self);
RACCommand *menuButtonPressed = [[RACCommand alloc] initWithEnabled:userIsLoggedInSignal signalBlock:^RACSignal *(id input) {
@strongify(self);
if (self.menuView.hidden) {
if (self.menuData != nil) {
return [RACSignal return: @YES];
}
return [[self.fetchUserMenuDataCommand execute:nil]
mapReplace:@YES];
} else {
return [RACSignal return:@NO];
}
}];
RACSignal *menuButtonSignal = [menuButtonPressed.executionSignals switchToLatest];
RACSignal *showHideMenuSignal = [RACSignal merge:@[[menuButtonSignal], [userIsLoggedInSignal ignore:@YES]]];
[self rac_liftSelector:@selector(showMenu:) withSignals: showHideMenuSignal];
[self rac_liftSelector:@selector(showLoading:) withSignals: self.fetchUserMenuDataCommand.executing];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment