Skip to content

Instantly share code, notes, and snippets.

@seivan
Forked from tonyarnold/then.m
Created August 15, 2013 14:59
Show Gist options
  • Select an option

  • Save seivan/6241538 to your computer and use it in GitHub Desktop.

Select an option

Save seivan/6241538 to your computer and use it in GitHub Desktop.
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];
@seivan
Copy link
Copy Markdown
Author

seivan commented Aug 15, 2013

Made a fork to show how to replace this with KVO blocks instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment