Created
November 8, 2013 07:01
-
-
Save mharju/7367279 to your computer and use it in GitHub Desktop.
Reactive Cocoa. Don't you just got to love it?
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
NSArray *items = @[_gainSlider, _frequencySaturation, _driveSlider]; | |
NSArray *signals = [[[items rac_sequence] map:^id(id value) { | |
return [value rac_highlightSignal]; | |
}] array]; | |
__block BOOL triggering = NO; | |
[[RACSignal merge:signals] | |
subscribeNext:^(RACTuple* value) { | |
if(triggering) { return; } | |
triggering = YES; | |
for(id item in items) { | |
if(item != value.first) { | |
[item setHighlighted:NO]; | |
} | |
} | |
triggering = NO; | |
}]; | |
FlatMapping color = ^RACStream *(RACTuple *value) { | |
NSColor *color = [value.second boolValue] ? almostWhite : unhighlight; | |
return [RACSignal return:color]; | |
}; | |
RAC(self.driveLabel, textColor) = [[_driveSlider rac_highlightSignal] flattenMap:color]; | |
RAC(self.driveValue, textColor) = [[_driveSlider rac_highlightSignal] flattenMap:color]; | |
RAC(self.gainLabel, textColor) = [[_gainSlider rac_highlightSignal] flattenMap:color]; | |
RAC(self.gainValue, textColor) = [[_gainSlider rac_highlightSignal] flattenMap:color]; | |
RAC(self.saturationLabel, textColor) = [[_frequencySaturation rac_highlightSignal] flattenMap:color]; | |
[[[_driveSlider rac_valueSignal] map:^id(id value) { | |
return [NSString stringWithFormat:@"%.1f", [value doubleValue]]; | |
}] subscribeNext:^(id value) { | |
[self.driveValue setStringValue:value]; | |
}]; | |
[[[_gainSlider rac_valueSignal] map:^id(id value) { | |
return [NSString stringWithFormat:@"%.1f", [value doubleValue]]; | |
}] subscribeNext:^(id value) { | |
[self.gainValue setStringValue:value]; | |
}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment