ReactiveCocoa / ReactiveViewModel

Model-View-ViewModel, using ReactiveCocoa
MIT License
1.96k stars 259 forks source link

inject protocol RVMViewModelReacting for using in couple RVMViewModel #23

Closed blnked closed 10 years ago

blnked commented 10 years ago

Please, review request to inject protocol

Recently I faced to using multiple ViewModels with one common protocol. And you know, I don't understand why not use protocol to avoid some writting like RVMViewModel <MyProtocol> *viewModel. Because, in this case a ViewController doesn't may find anything from RVMViewModel

for example:

@protocol MyProtocol <NSObject>

@interface MyClass1VM: RVMViewModel <MyProtocol>
@interface MyClass2VM: RVMViewModel <MyProtocol>

thus, we get next ...

@interface MyCustomVC : UIViewController
@property (nonatomic, strong) RVMViewModel <MyProtocol> *viewModel
@end

Perhaps, better to use in this case a protocol inheritance

@protocol MyProtocol <NSObject, RVMViewModelReacting>
jspahrsummers commented 10 years ago

Sorry, I don't fully understand the utility of this. Can you show us an example class that would implement this protocol, and specifically why it can't inherit from the RVMViewModel class?

blnked commented 10 years ago

Sorry, I don't fully understand the utility of this. Can you show us an example class that would implement this protocol, and specifically why it can't inherit from the RVMViewModel class?

For clarity, I've created a quick example. Please, compare branches master and protocol.

Please pay attention to the difference of writing:

@property (nonatomic, strong) RVMViewModel<RVMDetailVM> *viewModel; vs @property (nonatomic, strong) id<RVMDetailVM> viewModel;

jspahrsummers commented 10 years ago

It sounds like you just want to make it easier to refer to RVMViewModel properties that also have your custom protocol. Is that correct?

If so, why not use a typedef:

typedef RVMViewModel<RVMDetailVM> *RVMDetailVM;

@property (nonatomic, strong) RVMDetailVM viewModel;
blnked commented 10 years ago

Yep, correct

You're right, it can be option, but I didn't see any differences between typedef RVMViewModel<RVMDetailVM> *RVMDetailVM; and @property (nonatomic, strong) RVMViewModel<RVMDetailVM> *viewModel;

It's question about protocol as more flexible API of class. Perhaps, it only my opinion. you can close this pull request.

Anyway, thanks for excellent projects like ReactiveCocoa, ReactiveViewModel.

jspahrsummers commented 10 years ago

It's certainly true that protocols are more flexible.

However, the signals implemented in RVMViewModel are very complex, and I don't think third-party implementations outside of the main class would be a good idea, so I don't want to encourage that with a protocol.

Thanks for the suggestion, and for discussing it, though! :sparkles:

blnked commented 10 years ago

However, the signals implemented in RVMViewModel are very complex, and I don't think third-party implementations outside of the main class would be a good idea, so I don't want to encourage that with a protocol.

Agreed! It's make sense.