Skip to content

Commit

Permalink
Merge pull request #12 from grigaci/features/batchImprovements
Browse files Browse the repository at this point in the history
Batch improvements
  • Loading branch information
grigaci committed Dec 14, 2015
2 parents 44c648e + d3bd9f8 commit 67471b3
Show file tree
Hide file tree
Showing 37 changed files with 2,572 additions and 2,293 deletions.
14 changes: 6 additions & 8 deletions BIObjCHelpers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
4304A9B61B70D892009739B3 /* BIDatasourceTableViewTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 4304A9B51B70D892009739B3 /* BIDatasourceTableViewTestCase.m */; };
43329F6F1BFC7D6F0081FDA3 /* BIDatasourceBaseTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 43329F6E1BFC7D6F0081FDA3 /* BIDatasourceBaseTestCase.m */; };
435D59C01B622E8A00ECA859 /* BIMockHandlerTableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 435D59BF1B622E8A00ECA859 /* BIMockHandlerTableView.m */; };
43BE6C311B56882B001F0A00 /* libBIObjCHelpers.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 43BE6C251B56882B001F0A00 /* libBIObjCHelpers.a */; };
43BE6C731B5689CA001F0A00 /* NSBundle+BIExtra.m in Sources */ = {isa = PBXBuildFile; fileRef = 43BE6C461B5689C9001F0A00 /* NSBundle+BIExtra.m */; };
Expand Down Expand Up @@ -46,7 +47,6 @@
43DA594C1B6217F400ECAAC0 /* BITableViewTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 43DA594B1B6217F400ECAAC0 /* BITableViewTestCase.m */; };
43F23F761B9ED4B600CEAD8C /* BITableViewCellTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F23F751B9ED4B600CEAD8C /* BITableViewCellTestCase.m */; };
43F23F791B9EDA5500CEAD8C /* BIActivityIndicatorContainerViewTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F23F781B9EDA5500CEAD8C /* BIActivityIndicatorContainerViewTestCase.m */; };
43F23F7E1B9EFC0D00CEAD8C /* BIBatch.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F23F7B1B9EFC0D00CEAD8C /* BIBatch.m */; };
43F23F7F1B9EFC0D00CEAD8C /* BIBatchHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F23F7D1B9EFC0D00CEAD8C /* BIBatchHelpers.m */; };
43F23F811B9EFC6A00CEAD8C /* BIBatchRequestTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F23F801B9EFC6A00CEAD8C /* BIBatchRequestTestCase.m */; };
43F23F851B9F040C00CEAD8C /* BIBatchResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 43F23F841B9F040C00CEAD8C /* BIBatchResponse.m */; };
Expand All @@ -63,8 +63,8 @@
91E9ECE91B949D0D0009C4F1 /* BIDatasourceFeedCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91E9ECE81B949D0D0009C4F1 /* BIDatasourceFeedCollectionView.m */; };
91E9ECEC1B94A6BD0009C4F1 /* BIActivityIndicatorContainerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91E9ECEB1B94A6BD0009C4F1 /* BIActivityIndicatorContainerView.m */; };
91E9ECF01B94A6F10009C4F1 /* BICollectionViewActivityIndicatorReusableView.m in Sources */ = {isa = PBXBuildFile; fileRef = 91E9ECEF1B94A6F10009C4F1 /* BICollectionViewActivityIndicatorReusableView.m */; };
9437007F1BCD3F9C0063D2CC /* BILaunchStartersFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 9437007E1BCD3F9C0063D2CC /* BILaunchStartersFactory.m */; settings = {ASSET_TAGS = (); }; };
943700841BCD4E250063D2CC /* BILaunchStartersFactoryTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 943700831BCD4E250063D2CC /* BILaunchStartersFactoryTestCase.m */; settings = {ASSET_TAGS = (); }; };
9437007F1BCD3F9C0063D2CC /* BILaunchStartersFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 9437007E1BCD3F9C0063D2CC /* BILaunchStartersFactory.m */; };
943700841BCD4E250063D2CC /* BILaunchStartersFactoryTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 943700831BCD4E250063D2CC /* BILaunchStartersFactoryTestCase.m */; };
E59E667E65313C7B4DAF4C43 /* libPods-BIObjCHelpersTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = EBB3C6740A3FA0FB1D88D15E /* libPods-BIObjCHelpersTests.a */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -92,6 +92,7 @@

/* Begin PBXFileReference section */
4304A9B51B70D892009739B3 /* BIDatasourceTableViewTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BIDatasourceTableViewTestCase.m; sourceTree = "<group>"; };
43329F6E1BFC7D6F0081FDA3 /* BIDatasourceBaseTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BIDatasourceBaseTestCase.m; sourceTree = "<group>"; };
4355334F1B81B87F0052A128 /* _BITableView+Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "_BITableView+Internal.h"; path = "Views/TableView/_BITableView+Internal.h"; sourceTree = "<group>"; };
435D59BE1B622E8A00ECA859 /* BIMockHandlerTableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BIMockHandlerTableView.h; path = BIHandlerTableView/BIMockHandlerTableView.h; sourceTree = "<group>"; };
435D59BF1B622E8A00ECA859 /* BIMockHandlerTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BIMockHandlerTableView.m; path = BIHandlerTableView/BIMockHandlerTableView.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -157,8 +158,6 @@
43DA594B1B6217F400ECAAC0 /* BITableViewTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BITableViewTestCase.m; path = Views/TableView/BITableViewTestCase.m; sourceTree = "<group>"; };
43F23F751B9ED4B600CEAD8C /* BITableViewCellTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BITableViewCellTestCase.m; path = Views/TableView/Cell/BITableViewCellTestCase.m; sourceTree = "<group>"; };
43F23F781B9EDA5500CEAD8C /* BIActivityIndicatorContainerViewTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BIActivityIndicatorContainerViewTestCase.m; path = Views/TableView/ActivityIndicator/BIActivityIndicatorContainerViewTestCase.m; sourceTree = "<group>"; };
43F23F7A1B9EFC0D00CEAD8C /* BIBatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BIBatch.h; sourceTree = "<group>"; };
43F23F7B1B9EFC0D00CEAD8C /* BIBatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BIBatch.m; sourceTree = "<group>"; };
43F23F7C1B9EFC0D00CEAD8C /* BIBatchHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BIBatchHelpers.h; sourceTree = "<group>"; };
43F23F7D1B9EFC0D00CEAD8C /* BIBatchHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BIBatchHelpers.m; sourceTree = "<group>"; };
43F23F801B9EFC6A00CEAD8C /* BIBatchRequestTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BIBatchRequestTestCase.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -299,8 +298,6 @@
43BE6C3F1B5689C9001F0A00 /* Batch */ = {
isa = PBXGroup;
children = (
43F23F7A1B9EFC0D00CEAD8C /* BIBatch.h */,
43F23F7B1B9EFC0D00CEAD8C /* BIBatch.m */,
43F23F881B9F081200CEAD8C /* BIBatchRequest.h */,
43F23F891B9F081200CEAD8C /* BIBatchRequest.m */,
43F23F831B9F040C00CEAD8C /* BIBatchResponse.h */,
Expand Down Expand Up @@ -613,6 +610,7 @@
43BE6CE51B568ECB001F0A00 /* TableView */ = {
isa = PBXGroup;
children = (
43329F6E1BFC7D6F0081FDA3 /* BIDatasourceBaseTestCase.m */,
4304A9B51B70D892009739B3 /* BIDatasourceTableViewTestCase.m */,
43BE6CE61B568ECB001F0A00 /* BIDatasourceFeedTableViewTestCase.m */,
43BE6CE71B568ECB001F0A00 /* BIDatasourceFetchedTableViewTestCase.m */,
Expand Down Expand Up @@ -989,7 +987,6 @@
43F23F8A1B9F081200CEAD8C /* BIBatchRequest.m in Sources */,
43F23F7F1B9EFC0D00CEAD8C /* BIBatchHelpers.m in Sources */,
43BE6C7A1B5689CA001F0A00 /* BIDatasourceFetchedTableView.m in Sources */,
43F23F7E1B9EFC0D00CEAD8C /* BIBatch.m in Sources */,
91614A831B94790400D00EB2 /* _BIScrollViewProxy.m in Sources */,
43BE6C791B5689CA001F0A00 /* BIDatasourceFeedTableView.m in Sources */,
91614A951B94830600D00EB2 /* BIHandlerCollectionView.m in Sources */,
Expand Down Expand Up @@ -1023,6 +1020,7 @@
43BE6D051B568ECB001F0A00 /* BIMockStarter.m in Sources */,
4304A9B61B70D892009739B3 /* BIDatasourceTableViewTestCase.m in Sources */,
43BE6D001B568ECB001F0A00 /* BIHandlerTableViewTestCase.m in Sources */,
43329F6F1BFC7D6F0081FDA3 /* BIDatasourceBaseTestCase.m in Sources */,
43BE6CD01B568B1F001F0A00 /* BITestCaseCoreData.m in Sources */,
914D2CB51B57BB41009A9B4D /* BIBatchHelpersTestCase.m in Sources */,
43DA594C1B6217F400ECAAC0 /* BITableViewTestCase.m in Sources */,
Expand Down
52 changes: 0 additions & 52 deletions BIObjCHelpers/Batch/BIBatch.h

This file was deleted.

44 changes: 0 additions & 44 deletions BIObjCHelpers/Batch/BIBatch.m

This file was deleted.

48 changes: 46 additions & 2 deletions BIObjCHelpers/Batch/BIBatchRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
FOUNDATION_EXPORT const NSInteger kDefaultBatchRequestSize;

@class BIBatchResponse;
@class BIMutableBatchRequest;

typedef void(^BIBatchRequestCompletionBlock)(BIBatchResponse * __nonnull response);

Expand All @@ -32,7 +33,7 @@ typedef NS_ENUM(NSUInteger, BIBatchInsertPosition) {
* @brief Defines a set of data request values.
* Mostly used in table and collection views for inserting sets of data.
*/
@interface BIBatchRequest : NSObject
@interface BIBatchRequest : NSObject <NSCopying, NSMutableCopying>

- (nonnull instancetype)init NS_UNAVAILABLE;
+ (nonnull instancetype)new NS_UNAVAILABLE;
Expand Down Expand Up @@ -73,6 +74,49 @@ typedef NS_ENUM(NSUInteger, BIBatchInsertPosition) {
* @brief Specify an index from where to start inserting the new elements that will be fetched.
* Defaults to BIBatchInsertPositionBottom;
*/
@property (nonatomic, assign) NSUInteger insertPosition;
@property (nonatomic, assign, readwrite) NSUInteger insertPosition;

/*!
* @brief Additional flags that can be set for a batch request.
*/
@property (nonatomic, assign, readonly) NSUInteger options;

/*!
* @brief Overriden method for returning the exact class type for a copied object.
*/
- (nonnull BIBatchRequest *)copy;

/*!
* @brief Overriden method for returning the exact class type for a mutable copy.
*/
- (nonnull BIMutableBatchRequest *)mutableCopy;

@end


/*!
* Mutable version of a batch request.
*/
@interface BIMutableBatchRequest : BIBatchRequest

/*!
* @brief Size of the batch that is fetching.
*/
@property (nonatomic, assign, readwrite) NSUInteger batchSize;

/*!
* @brief Section index for which data is fetching.
*/
@property (nonatomic, assign, readwrite) NSUInteger sectionIndex;

/*!
* @brief Code block to be called when fetching is done or in case of error.
*/
@property (nonatomic, copy, nullable, readwrite) BIBatchRequestCompletionBlock completionBlock;

/*!
* @brief Additional flags that can be set for a batch request.
*/
@property (nonatomic, assign, readwrite) NSUInteger options;

@end
51 changes: 51 additions & 0 deletions BIObjCHelpers/Batch/BIBatchRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @interface BIBatchRequest ()
@property (nonatomic, assign, readwrite) NSUInteger batchSize;
@property (nonatomic, assign, readwrite) NSUInteger sectionIndex;
@property (nonatomic, copy, nullable, readwrite) BIBatchRequestCompletionBlock completionBlock;
@property (nonatomic, assign, readwrite) NSUInteger options;

@end

Expand Down Expand Up @@ -42,4 +43,54 @@ - (instancetype)initWithCompletionBlock:(BIBatchRequestCompletionBlock)completio
completionBlock:completionBlock];
}

#pragma mark - NSCopying methods

- (id)copyWithZone:(nullable NSZone *)zone {
BIBatchRequest *copy = [[BIBatchRequest allocWithZone:zone] initWithCompletionBlock:self.completionBlock];
copy.batchSize = self.batchSize;
copy.sectionIndex = self.sectionIndex;
copy.insertPosition = self.insertPosition;
copy.options = self.options;
return copy;
}

#pragma mark - NSMutableCopying methods

- (id)mutableCopyWithZone:(nullable NSZone *)zone {
BIMutableBatchRequest *mutableCopy = [[BIMutableBatchRequest allocWithZone:zone] initWithCompletionBlock:self.completionBlock];
mutableCopy.batchSize = self.batchSize;
mutableCopy.sectionIndex = self.sectionIndex;
mutableCopy.insertPosition = self.insertPosition;
mutableCopy.options = self.options;
return mutableCopy;
}

#pragma mark - NSObject methods

- (nonnull BIBatchRequest *)copy {
return [super copy];
}

- (nonnull BIMutableBatchRequest *)mutableCopy {
return [super mutableCopy];
}

@end

@implementation BIMutableBatchRequest

@dynamic batchSize;
@dynamic sectionIndex;
@dynamic completionBlock;
@dynamic options;

#pragma mark - Init methods

- (nonnull instancetype)initWithSection:(NSUInteger)sectionIndex
batchSize:(NSUInteger)batchSize
completionBlock:(nullable BIBatchRequestCompletionBlock)completionBlock {
self = [super initWithSection:sectionIndex batchSize:batchSize completionBlock:completionBlock];
return self;
}

@end
2 changes: 2 additions & 0 deletions BIObjCHelpers/Datasource/Base/BIDatasourceBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

@interface BIDatasourceBase : BILifecycle

@property (nonatomic, strong, nonnull, readonly) NSHashTable *operations;

@end
16 changes: 16 additions & 0 deletions BIObjCHelpers/Datasource/Base/BIDatasourceBase.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@

#import "BIDatasourceBase.h"

@interface BIDatasourceBase ()

@property (nonatomic, strong, nonnull, readwrite) NSHashTable *operations;

@end


@implementation BIDatasourceBase

#pragma mark - Property methods

- (NSHashTable *)operations {
if (!_operations) {
_operations = [NSHashTable weakObjectsHashTable];
}
return _operations;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ - (void)handleFetchBatchResponseWithFailure:(nonnull BIBatchResponse *)batchResp
}

- (void)handleFetchBatchResponseWithSuccess:(nonnull BIBatchResponse *)batchResponse {
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:batchResponse.indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];

if (batchResponse.indexPaths.count) {
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:batchResponse.indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
[self handleFetchBatchResponseCommon:batchResponse];
}

Expand Down
2 changes: 0 additions & 2 deletions BIObjCHelpers/Interface/BIObjCHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#import "BIDatasourceFetchedTableView.h"
#import "BIDatasourceFetchedCollectionView.h"
#import "BIDatasourceFeedTableView.h"
#import "BIBatch.h"

// Handlers
#import "BIHandlerBase.h"
Expand All @@ -34,6 +33,5 @@
#import "NSDate+BIAttributedString.h"

// Batch
#import "BIBatch.h"
#import "BIBatchRequest.h"
#import "BIBatchResponse.h"
Loading

0 comments on commit 67471b3

Please sign in to comment.