Created
February 4, 2014 14:58
-
-
Save stigi/8805151 to your computer and use it in GitHub Desktop.
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
- (void)bindFormCell:(MYFormCell *)cell toViewModel:(MYFormViewModel *)viewModel withKeyPath:(NSString *)keyPath | |
{ | |
// signal passing in cell as an observer will complete the signal when cell is dealloced | |
// (as well as (read "OR") when viewModel is dealloced) | |
RACSignal *textInputSignal = [viewModel rac_valuesForKeyPath:keyPath observer:cell]; | |
@weakify(cell); | |
RACDisposable *inputDisposable = [textInputSignal subscribeNext:^(NSString *text) { | |
@strongify(cell); | |
cell.textField.text = text; | |
}]; | |
RACSignal *textOutputSignal = [cell.textField rac_textSignal]; | |
@weakify(viewModel); | |
RACDisposable *outputDisposable = [textOutputSignal subscribeNext:^(NSString *text) { | |
@strongify(viewModel); | |
[viewModel setValue:text forKey:keyPath]; | |
}]; | |
// whenever the cell is reused unbind those signals | |
[[[cell rac_prepareForReuseSignal] take:1] subscribeNext:^(id x) { | |
[inputDisposable dispose]; | |
[outputDisposable dispose]; | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment