Vote count:
0
I have started setting up my view models so they automatically unbind/bind themselves to any model they represent.
I'm relatively new to ReactiveCocoa and want to know if what I'm doing is bad/good practice or if there's a better way to do it.
For example, if I have a view model that represents a movie model, I would set it up like this:
-(void)bind{
[RACObserve(self, movieModel) subscribeNext:^(id x) {
[self unbindMovieModel];
[self bindMovieModel];
}];
}
-(void)unbindMovieModel{}
-(void)bindMovieModel{
self.titleSignal = [RACObserve(self.movieModel, title)
takeUntil:[self rac_signalForSelector:@selector(unbindMovieModel)];
self.averageRatingSignal = [[self.movieModel currAverageRating]
takeUntil:[self rac_signalForSelector:@selector(unbindMovieModel)];
//Setup some more complex signals, etc...
}
Now if at any point I do:
self.movieModel = newModel;
The view model will unbind from the old movieModel and bind itself to newModel.
Is there a better way? Is this not "reactive"? Any feedback would be really appreciated.
asked 53 secs ago
Should I rebind models in ReactiveCocoa MVVM?
Aucun commentaire:
Enregistrer un commentaire