Skip to content
Browse files

Making changes based upon issue #406

  • Loading branch information...
1 parent 5afaf72 commit 4fc2d410af63a83b5786d4254d2679e1ade3cf6f @KyleLeneau committed Mar 28, 2013
Showing with 12 additions and 3 deletions.
  1. +12 −3 ReactiveCocoaFramework/ReactiveCocoa/UIBarButtonItem+RACCommandSupport.m
View
15 ReactiveCocoaFramework/ReactiveCocoa/UIBarButtonItem+RACCommandSupport.m
@@ -10,10 +10,13 @@
#import <ReactiveCocoa/RACCommand.h>
#import <ReactiveCocoa/RACSubscriptingAssignmentTrampoline.h>
#import <ReactiveCocoa/NSObject+RACPropertySubscribing.h>
+#import <ReactiveCocoa/RACSignal+Operations.h>
+#import <ReactiveCocoa/RACDisposable.h>
#import <objc/runtime.h>
static void * UIControlRACCommandKey = &UIControlRACCommandKey;
+static void * UIControlRACCommandSignalKey = &UIControlRACCommandSignalKey;
@implementation UIBarButtonItem (RACCommandSupport)
@@ -24,11 +27,17 @@ - (RACCommand *)rac_command {
- (void)setRac_command:(RACCommand *)command {
objc_setAssociatedObject(self, UIControlRACCommandKey, command, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- self.enabled = command != nil ? command.canExecute : YES;
-
if (command == nil) return;
- RAC(self.enabled) = RACAbleWithStart(command, canExecute);
+ // Check for stored signal
+ RACDisposable *existingSignal = objc_getAssociatedObject(self, UIControlRACCommandSignalKey);
+ if (existingSignal != nil) {
+ // Remove the old signal to add a new one
+ [existingSignal dispose];
+ }
+
+ RACDisposable *newSignal = [RACAbleWithStart(command, canExecute) toProperty:@"enabled" onObject:self];
+ objc_setAssociatedObject(self, UIControlRACCommandSignalKey, newSignal, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self rac_hijackActionAndTargetIfNeeded];
}

0 comments on commit 4fc2d41

Please sign in to comment.
Something went wrong with that request. Please try again.