mirror of
https://github.com/zhigang1992/FunctionalReactivePixels.git
synced 2026-01-12 22:47:31 +08:00
Migrated FRPFullSizePhotoViewModel to ReactiveViewModel.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user