optional modules
This commit is contained in:
parent
d545af3278
commit
5cdb0414bb
@ -191,29 +191,32 @@
|
|||||||
|
|
||||||
// Never use the cache.
|
// Never use the cache.
|
||||||
completionHandler(nil,nil);
|
completionHandler(nil,nil);
|
||||||
} else if (requestParameters.pageType.length != 0 && requestParameters.modules.count > 0) {
|
} else {
|
||||||
|
NSArray *modules = [requestParameters allModules];
|
||||||
|
if (requestParameters.pageType.length != 0 && modules.count > 0) {
|
||||||
|
|
||||||
// Check cache function for page json is already in the cache.
|
// Check cache function for page json is already in the cache.
|
||||||
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
||||||
|
|
||||||
// Check cache function for modules already in the cache.
|
// Check cache function for modules already in the cache.
|
||||||
NSDictionary *pageDictionary = jsonDictionary;
|
NSDictionary *pageDictionary = jsonDictionary;
|
||||||
[[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
[[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
||||||
completionHandler(pageDictionary,jsonDictionary);
|
completionHandler(pageDictionary,jsonDictionary);
|
||||||
|
}];
|
||||||
}];
|
}];
|
||||||
}];
|
} else if (requestParameters.pageType.length != 0) {
|
||||||
} else if (requestParameters.pageType.length != 0) {
|
|
||||||
|
|
||||||
// Check cache function if page json is already in the cache.
|
// Check cache function if page json is already in the cache.
|
||||||
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
[[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
||||||
completionHandler(jsonDictionary,nil);
|
completionHandler(jsonDictionary,nil);
|
||||||
}];
|
}];
|
||||||
} else if (requestParameters.modules.count > 0) {
|
} else if (modules > 0) {
|
||||||
|
|
||||||
// Check cache function if modules already in the cache.
|
// Check cache function if modules already in the cache.
|
||||||
[[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
[[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
|
||||||
completionHandler(nil,jsonDictionary);
|
completionHandler(nil,jsonDictionary);
|
||||||
}];
|
}];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,16 +242,21 @@
|
|||||||
// Check if the page was found in the cache.
|
// Check if the page was found in the cache.
|
||||||
BOOL pageNotInCache = loadObject.operation.requestParameters.pageType && !loadObject.pageDataFromCache;
|
BOOL pageNotInCache = loadObject.operation.requestParameters.pageType && !loadObject.pageDataFromCache;
|
||||||
|
|
||||||
// Check all modules were found in the cache
|
// Check all required modules were found in the cache
|
||||||
NSMutableArray *modulesNotInCache = [NSMutableArray array];
|
NSMutableArray *modulesNotInCache = [NSMutableArray array];
|
||||||
for (NSString *module in loadObject.operation.requestParameters.modules) {
|
NSMutableArray *requiredModules = [NSMutableArray arrayWithArray:loadObject.operation.requestParameters.modules];
|
||||||
|
for (NSString *module in [loadObject.operation.requestParameters allModules]) {
|
||||||
if (![loadObject.modulesJSON objectForKey:module]) {
|
if (![loadObject.modulesJSON objectForKey:module]) {
|
||||||
|
// Missing a module.
|
||||||
[modulesNotInCache addObject:module];
|
[modulesNotInCache addObject:module];
|
||||||
|
} else {
|
||||||
|
// Received a required module.
|
||||||
|
[requiredModules removeObject:module];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MVMCoreRequestParameters *requestParametersForServer = nil;
|
MVMCoreRequestParameters *requestParametersForServer = nil;
|
||||||
if (pageNotInCache || modulesNotInCache.count > 0) {
|
if (pageNotInCache || requiredModules.count > 0) {
|
||||||
|
|
||||||
// We are missing data, will need to go to server.
|
// We are missing data, will need to go to server.
|
||||||
requestParametersForServer = [loadObject.operation.requestParameters copy];
|
requestParametersForServer = [loadObject.operation.requestParameters copy];
|
||||||
|
|||||||
@ -29,6 +29,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) {
|
|||||||
|
|
||||||
// request parameters
|
// request parameters
|
||||||
@property (nullable, strong, nonatomic) NSString *pageType;
|
@property (nullable, strong, nonatomic) NSString *pageType;
|
||||||
|
@property (nullable, strong, nonatomic) NSArray *optionalModules;
|
||||||
@property (nullable, strong, nonatomic) NSArray *modules;
|
@property (nullable, strong, nonatomic) NSArray *modules;
|
||||||
@property (nullable, strong, nonatomic) NSDictionary *parameters;
|
@property (nullable, strong, nonatomic) NSDictionary *parameters;
|
||||||
@property (nullable, strong, nonatomic) NSData *imageData;
|
@property (nullable, strong, nonatomic) NSData *imageData;
|
||||||
@ -120,4 +121,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) {
|
|||||||
// Sets the load style based on the server sent presentationStyle
|
// Sets the load style based on the server sent presentationStyle
|
||||||
- (void)setMFLoadStyleBasedOnPresentationStyle:(nonnull NSString *)presentationStyle;
|
- (void)setMFLoadStyleBasedOnPresentationStyle:(nonnull NSString *)presentationStyle;
|
||||||
|
|
||||||
|
/// Returns optional and required modules
|
||||||
|
- (nullable NSArray *)allModules;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@ -116,6 +116,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (nullable NSArray *)allModules {
|
||||||
|
NSMutableSet *set = [NSMutableSet setWithArray:self.optionalModules];
|
||||||
|
[set addObjectsFromArray:self.modules];
|
||||||
|
return [set allObjects];
|
||||||
|
}
|
||||||
|
|
||||||
- (id)copyWithZone:(nullable NSZone *)zone {
|
- (id)copyWithZone:(nullable NSZone *)zone {
|
||||||
|
|
||||||
MVMCoreRequestParameters *copyObject = [[MVMCoreRequestParameters alloc] init];
|
MVMCoreRequestParameters *copyObject = [[MVMCoreRequestParameters alloc] init];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user