Created
June 17, 2014 06:44
-
-
Save bobspryn/6ffad42a7a44296dd8f8 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) 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