Created
October 12, 2012 19:35
-
-
Save joshaber/3881052 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
// Here, rowView is a weak pointer to the view's superview. | |
RAC(self.layer.contents) = [[[[RACAble(self.rowView.selected) distinctUntilChanged] injectObjectWeakly:self] | |
doNext:^(RACTuple *x) { | |
CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"contents"]; | |
fade.duration = 0.15; | |
[[x.last layer] addAnimation:fade forKey:@"animateContents"]; | |
}] select:^id(RACTuple *x) { | |
return ([x.first boolValue] ? [self highlightedGradient] : [self standardGradient]); | |
}]; | |
// So we want our KVO observation to stop when `rowView` is dealloc'd. But note | |
// that RACAble(self.rowView.selected) is really: | |
// | |
// [self rac_subscribableForKeyPath:@"self.rowView.selected" onObject:self] | |
// | |
// No where in that can RAC determine that the KVO observation should be tied | |
// to `rowView`. It's just a key path relative to self. So we really want: | |
// | |
// [self.rowView rac_subscribableForKeyPath:@"selected" onObject:self] | |
// | |
// That way RAC knows to keep the KVO observation around only as long as self | |
// and `rowView` are alive. We can then write that as: | |
// | |
// RACAble(self.rowView, selected) | |
// | |
// This is less than ideal because now whenever `rowView` changes, you have to | |
// re-subscribe. It's a pain in the ass that we run into too but I don't have a | |
// great way to solve it. (This is what happens with a language without garbage | |
// collection and poor static introspection.) | |
// | |
// Actually @jspahrsummers' block craziness could probably solve this by | |
// knowing the root object for the keypath... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment