-
-
Save seivan/6241538 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| self.currentlyLoggingIn = NO; | |
| self.didLoginSubject = [RACSubject subject]; | |
| self.loginCommand = [RACCommand commandWithCanExecuteSignal:[RACSignal | |
| combineLatest:@[self.usernameTextField.rac_textSignal, | |
| self.passwordTextField.rac_textSignal, | |
| RACObserve(self, currentlyLoggingIn)] | |
| reduce:^(NSString *username, NSString *password, NSNumber *currentlyLoggingIn) { | |
| return @(username.length > 0 && password.length > 0 && NO == currentlyLoggingIn.boolValue ); | |
| }]]; | |
| @weakify(self); | |
| // Every time loginCommand is triggered… | |
| RACSignal *loginResult = [[self.loginCommand then:^{ | |
| @strongify(self); | |
| // Try logging in, and return the result. | |
| // | |
| // -materialize means that we wrap each next value or error in | |
| // a RACEvent. This means that even if the API hits an error, the | |
| // loginResult signal will still be valid. | |
| return [[[TCBCADNController sharedInstance] loginAccountWithUserName:self.usernameTextField.stringValue password:self.passwordTextField.stringValue] materialize]; | |
| }] replayLazily]; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Made a fork to show how to replace this with KVO blocks instead.