Migrated FRPFullSizePhotoViewModel to ReactiveViewModel.

This commit is contained in:
Ash Furrow
2013-10-25 17:13:02 -04:00
parent 30e2d9e9f6
commit d9d6382f4b
5 changed files with 14 additions and 21 deletions

View File

@@ -10,10 +10,11 @@
@class FRPPhotoModel;
@interface FRPFullSizePhotoViewModel : NSObject
@interface FRPFullSizePhotoViewModel : RVMViewModel
-(instancetype)initWithPhotoModelArray:(NSArray *)photoModelArray initialPhotoIndex:(NSInteger)initialPhotoIndex;
@property (nonatomic, readonly, strong) RACTuple *model;
@property (nonatomic, readonly) NSArray *photoArray;
@property (nonatomic, readonly) NSInteger initialPhotoIndex;
@property (nonatomic, readonly) NSString *initialPhotoName;

View File

@@ -14,28 +14,22 @@
@interface FRPFullSizePhotoViewModel ()
// Private access
@property (nonatomic, strong) NSArray *photoArray;
@property (nonatomic, assign) NSInteger initialPhotoIndex;
@end
@implementation FRPFullSizePhotoViewModel
-(instancetype)initWithPhotoModelArray:(NSArray *)photoModelArray initialPhotoIndex:(NSInteger)initialPhotoIndex {
self = [self init];
if (!self) return nil;
self.photoArray = photoModelArray;
self.initialPhotoIndex = initialPhotoIndex;
return self;
}
-(NSString *)initialPhotoName {
return [self.photoArray[self.initialPhotoIndex] photoName];
}
-(NSInteger)initialPhotoIndex {
return [self.model.second integerValue];
}
-(NSArray *)photoArray {
return self.model.first;
}
-(FRPPhotoModel *)photoModelAtIndex:(NSInteger)index {
if (index < 0 || index > self.photoArray.count - 1) {
// Index was out of bounds, return nil

View File

@@ -71,7 +71,7 @@ static NSString *CellIdentifier = @"Cell";
@strongify(self);
NSIndexPath *indexPath = arguments.second;
FRPFullSizePhotoViewModel *viewModel = [[FRPFullSizePhotoViewModel alloc] initWithPhotoModelArray:self.viewModel.model initialPhotoIndex:indexPath.item];
FRPFullSizePhotoViewModel *viewModel = [[FRPFullSizePhotoViewModel alloc] initWithModel:RACTuplePack(self.viewModel.model, @(indexPath.item))];
FRPFullSizePhotoViewController *viewController = [[FRPFullSizePhotoViewController alloc] init];
viewController.viewModel = viewModel;

View File

@@ -13,8 +13,6 @@
@interface FRPGalleryViewModel ()
@property (nonatomic, strong) NSArray *photosArray;
@end
@implementation FRPGalleryViewModel
@@ -23,7 +21,7 @@
self = [super init];
if (!self) return nil;
RAC(self, photosArray) = [[[FRPPhotoImporter importPhotos] logError] catchTo:[RACSignal empty]];
RAC(self, model) = [[[FRPPhotoImporter importPhotos] logError] catchTo:[RACSignal empty]];
return self;
}

View File

@@ -55,7 +55,7 @@
@weakify(self);
[[self rac_signalForSelector:@selector(viewDidAppear:)] subscribeNext:^(id x) {
@strongify(self);
if (self.presentedViewController != nil) {
if (self.presentedViewController == nil) {
[SVProgressHUD show];
[self.viewModel.loadPhotosFromNetworkCommand execute:nil];