From 5cdb0414bbb20ed1d4a6c04c029f7c7e790c0b21 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Fri, 29 Jan 2021 10:18:20 -0500 Subject: [PATCH] optional modules --- .../MVMCoreLoadRequestOperation.m | 52 +++++++++++-------- .../LoadHandling/MVMCoreRequestParameters.h | 4 ++ .../LoadHandling/MVMCoreRequestParameters.m | 6 +++ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index 966700a..29f35b3 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -191,29 +191,32 @@ // Never use the cache. 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. - [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { + // Check cache function for page json is already in the cache. + [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - // Check cache function for modules already in the cache. - NSDictionary *pageDictionary = jsonDictionary; - [[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - completionHandler(pageDictionary,jsonDictionary); + // Check cache function for modules already in the cache. + NSDictionary *pageDictionary = jsonDictionary; + [[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable 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. - [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - completionHandler(jsonDictionary,nil); - }]; - } else if (requestParameters.modules.count > 0) { - - // Check cache function if modules already in the cache. - [[MVMCoreCache sharedCache] fetchJSONForModules:requestParameters.modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) { - completionHandler(nil,jsonDictionary); - }]; + // Check cache function if page json is already in the cache. + [[MVMCoreCache sharedCache] fetchJSONForPageType:requestParameters.pageType completionHandler:^(NSDictionary * _Nullable jsonDictionary) { + completionHandler(jsonDictionary,nil); + }]; + } else if (modules > 0) { + + // Check cache function if modules already in the cache. + [[MVMCoreCache sharedCache] fetchJSONForModules:modules completionHandler:^(NSDictionary * _Nullable jsonDictionary) { + completionHandler(nil,jsonDictionary); + }]; + } } } @@ -239,16 +242,21 @@ // Check if the page was found in the cache. 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]; - 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]) { + // Missing a module. [modulesNotInCache addObject:module]; + } else { + // Received a required module. + [requiredModules removeObject:module]; } } MVMCoreRequestParameters *requestParametersForServer = nil; - if (pageNotInCache || modulesNotInCache.count > 0) { + if (pageNotInCache || requiredModules.count > 0) { // We are missing data, will need to go to server. requestParametersForServer = [loadObject.operation.requestParameters copy]; diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h index df2aa69..7dbe729 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.h @@ -29,6 +29,7 @@ typedef NS_ENUM(NSInteger, MFLoadStyle) { // request parameters @property (nullable, strong, nonatomic) NSString *pageType; +@property (nullable, strong, nonatomic) NSArray *optionalModules; @property (nullable, strong, nonatomic) NSArray *modules; @property (nullable, strong, nonatomic) NSDictionary *parameters; @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 - (void)setMFLoadStyleBasedOnPresentationStyle:(nonnull NSString *)presentationStyle; +/// Returns optional and required modules +- (nullable NSArray *)allModules; + @end diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m index 5279dcc..b8e5877 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreRequestParameters.m @@ -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 { MVMCoreRequestParameters *copyObject = [[MVMCoreRequestParameters alloc] init];