move module from page to mfviewcontroller
This commit is contained in:
parent
bd365d60d2
commit
868593aabe
@ -131,6 +131,9 @@
|
||||
// Returns an array of modules to observe for when we receive a response with JSON. Subclass this to have the ui update when the returned page types are cached.
|
||||
- (nullable NSArray *)modulesToListenFor;
|
||||
|
||||
/// Aggregated with modulesToListenFor. Returns an array of modules to observe based on the page itself. Subclass this to go into the page logic and see if it dictates any modules are needed. Important: This also updates in the requiredModules in the view controller mapping, so that future page loads account for these modules.
|
||||
- (nullable NSArray *)requiredModulesFromPageJSON:(nullable NSDictionary *)page;
|
||||
|
||||
// The function that gets called by the notification center when the JSON is updated.
|
||||
- (void)responseJSONUpdated:(nonnull NSNotification *)notification;
|
||||
|
||||
|
||||
@ -93,6 +93,7 @@
|
||||
#pragma mark - Functions To Subclass
|
||||
|
||||
- (BOOL)shouldFinishProcessingLoad:(nonnull MVMCoreLoadObject *)loadObject error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error {
|
||||
[self updateRequiredModulesForPageJSON:loadObject.pageJSON];
|
||||
self.loadObject = loadObject;
|
||||
self.pageType = loadObject.pageType;
|
||||
return YES;
|
||||
@ -208,6 +209,20 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (nullable NSArray *)requiredModulesFromPageJSON:(nullable NSDictionary *)page {
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (nullable NSArray *)updateRequiredModulesForPageJSON:(nullable NSDictionary *)page {
|
||||
// get new needed modules and add them to the mapping for future loads.
|
||||
NSArray *newRequiredModules = [self requiredModulesFromPageJSON:page];
|
||||
NSString *pageType = [page string:KeyPageType];
|
||||
if (newRequiredModules && pageType) {
|
||||
[[MVMCoreViewControllerMappingObject sharedViewControllerMappingObject] addRequiredModulesToMapping:newRequiredModules forPageType:pageType];
|
||||
}
|
||||
return newRequiredModules;
|
||||
}
|
||||
|
||||
- (void)responseJSONUpdated:(nonnull NSNotification *)notification {
|
||||
|
||||
// Checks for a page we are listening for.
|
||||
@ -223,11 +238,22 @@
|
||||
}];
|
||||
|
||||
// Checks for modules we are listening for.
|
||||
NSArray *modulesListeningFor = [self modulesToListenFor];
|
||||
NSDictionary *modules = [notification.userInfo dict:KeyModuleMap];
|
||||
NSMutableArray *modulesListeningFor = [NSMutableArray array];
|
||||
NSArray *modules = [self modulesToListenFor];
|
||||
if (modules) {
|
||||
[modulesListeningFor addObjectsFromArray:modules];
|
||||
}
|
||||
|
||||
// Check if the page dictates if there are any new modules to load. Would eventually like to consolidate this and modulesToListenFor somehow.
|
||||
NSArray *requiredForPage = [self updateRequiredModulesForPageJSON:pageUpdated];
|
||||
if (requiredForPage) {
|
||||
[modulesListeningFor addObjectsFromArray:requiredForPage];
|
||||
}
|
||||
|
||||
NSDictionary *modulesReceived = [notification.userInfo dict:KeyModuleMap];
|
||||
__block NSMutableDictionary *modulesUpdated = [NSMutableDictionary dictionary];
|
||||
[modulesListeningFor enumerateObjectsUsingBlock:^(NSString * _Nonnull moduleToListenFor, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
NSDictionary *module = [modules dict:moduleToListenFor];
|
||||
NSDictionary *module = [modulesReceived dict:moduleToListenFor];
|
||||
if (module) {
|
||||
[modulesUpdated setObject:module forKey:moduleToListenFor];
|
||||
}
|
||||
|
||||
@ -65,14 +65,17 @@ open class ModuleMolecule: ViewConstrainingView {
|
||||
}
|
||||
|
||||
public override static func requiredModules(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject?>?) -> [String]? {
|
||||
guard let moduleName = json?.optionalStringForKey("moduleName"), let _ = delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) else {
|
||||
let moduleName = json?.optionalStringForKey("moduleName")
|
||||
if moduleName == nil || delegateObject?.moleculeDelegate?.getModuleWithName(moduleName) == nil {
|
||||
if let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), code: CoreUIErrorCode.ErrorCodeModuleMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) {
|
||||
error?.pointee = errorObject
|
||||
MVMCoreUILoggingHandler.shared()?.addError(toLog: errorObject)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return [moduleName]
|
||||
if let moduleName = moduleName {
|
||||
return [moduleName]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIViewConstrainingProtocol
|
||||
|
||||
@ -11,20 +11,6 @@ import UIKit
|
||||
open class MoleculeListTemplate: ThreeLayerTableViewController {
|
||||
var moleculesInfo: [(identifier: String, class: AnyClass, molecule: [AnyHashable: Any])]?
|
||||
var modulesRequired: NSMutableArray?
|
||||
|
||||
open override func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject>) -> Bool {
|
||||
var shouldFinish = super.shouldFinishProcessingLoad(loadObject, error: error)
|
||||
guard shouldFinish else {
|
||||
return shouldFinish
|
||||
}
|
||||
|
||||
if let firstError = setup()?.firstObject as? MVMCoreErrorObject {
|
||||
// Don't continue if there was an error loading needed modules.
|
||||
error.pointee = firstError
|
||||
shouldFinish = false
|
||||
}
|
||||
return shouldFinish
|
||||
}
|
||||
|
||||
open override func viewForTop() -> UIView {
|
||||
guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"),
|
||||
@ -44,7 +30,6 @@ open class MoleculeListTemplate: ThreeLayerTableViewController {
|
||||
|
||||
open override func newDataBuildScreen() {
|
||||
super.newDataBuildScreen()
|
||||
_ = setup()
|
||||
registerWithTable()
|
||||
}
|
||||
|
||||
@ -105,8 +90,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController {
|
||||
}
|
||||
|
||||
open override func modulesToListenFor() -> [Any]? {
|
||||
// Get all of the molecules that need modules.
|
||||
return modulesRequired as? [Any]
|
||||
return loadObject?.requestParameters?.modules
|
||||
}
|
||||
|
||||
// MARK: - Convenience
|
||||
@ -134,24 +118,27 @@ open class MoleculeListTemplate: ThreeLayerTableViewController {
|
||||
}
|
||||
|
||||
/// Sets up the header, footer, molecule list and ensures no errors loading all content.
|
||||
func setup() -> NSMutableArray? {
|
||||
func setup(fromPageJSON page: [AnyHashable : Any]?) {
|
||||
let modules: NSMutableArray = []
|
||||
let errors: NSMutableArray = []
|
||||
let delegate = delegateObject() as? MVMCoreUIDelegateObject
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: loadObject?.pageJSON?.optionalDictionaryForKey("header"), delegateObject: delegate, moduleList: modules, errorList: errors)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), delegateObject: delegate, moduleList: modules, errorList: errors)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: page?.optionalDictionaryForKey("header"), delegateObject: delegate, moduleList: modules, errorList: nil)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: page?.optionalDictionaryForKey("footer"), delegateObject: delegate, moduleList: modules, errorList: nil)
|
||||
|
||||
var moleculeList: [(identifier: String, class: AnyClass, molecule: [AnyHashable: Any])] = []
|
||||
if let molecules = loadObject?.pageJSON?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] {
|
||||
if let molecules = page?.optionalArrayForKey(KeyMolecules) as? [[AnyHashable: Any]] {
|
||||
for molecule in molecules {
|
||||
if let info = getMoleculeInfo(with: molecule) {
|
||||
moleculeList.append(info)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: molecule, delegateObject: delegate, moduleList: modules, errorList: errors)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: molecule, delegateObject: delegate, moduleList: modules, errorList: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
moleculesInfo = moleculeList
|
||||
modulesRequired = modules
|
||||
return errors.count > 0 ? errors : nil
|
||||
}
|
||||
|
||||
open override func requiredModules(fromPageJSON page: [AnyHashable : Any]?) -> [Any]? {
|
||||
setup(fromPageJSON: page)
|
||||
return modulesRequired as? [Any]
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,17 +9,6 @@
|
||||
import UIKit
|
||||
|
||||
public class MoleculeStackTemplate: ThreeLayerViewController {
|
||||
var modulesRequired: NSMutableArray?
|
||||
|
||||
public override func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject>) -> Bool {
|
||||
var shouldFinish = super.shouldFinishProcessingLoad(loadObject, error: error)
|
||||
if shouldFinish, let firstError = modulesNeeded().errors?.firstObject as? MVMCoreErrorObject {
|
||||
// Don't continue if there was an error loading needed modules.
|
||||
error.pointee = firstError
|
||||
shouldFinish = false
|
||||
}
|
||||
return shouldFinish
|
||||
}
|
||||
|
||||
public override func spaceBetweenTopAndMiddle() -> CGFloat? {
|
||||
return 0
|
||||
@ -58,19 +47,20 @@ public class MoleculeStackTemplate: ThreeLayerViewController {
|
||||
}
|
||||
|
||||
public override func modulesToListenFor() -> [Any]? {
|
||||
// Get all of the molecules that need modules.
|
||||
return modulesNeeded().modules as? [Any]
|
||||
return loadObject?.requestParameters?.modules
|
||||
}
|
||||
|
||||
open override func requiredModules(fromPageJSON page: [AnyHashable : Any]?) -> [Any]? {
|
||||
return modulesNeeded() as? [Any]
|
||||
}
|
||||
|
||||
/// Gets the modules needed.
|
||||
func modulesNeeded() -> (modules: NSMutableArray?, errors: NSMutableArray?) {
|
||||
func modulesNeeded() -> NSMutableArray? {
|
||||
let modules: NSMutableArray = []
|
||||
let errors: NSMutableArray = []
|
||||
let delegate = delegateObject() as? MVMCoreUIDelegateObject
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: loadObject?.pageJSON?.optionalDictionaryForKey("header"), delegateObject: delegate, moduleList: modules, errorList: errors)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), delegateObject: delegate, moduleList: modules, errorList: errors)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: loadObject?.pageJSON?.optionalDictionaryForKey("moleculeStack"), delegateObject: delegate, moduleList: modules, errorList: errors)
|
||||
modulesRequired = modules
|
||||
return (modules.count > 0 ? modules : nil, errors.count > 0 ? errors : nil)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: loadObject?.pageJSON?.optionalDictionaryForKey("header"), delegateObject: delegate, moduleList: modules, errorList: nil)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: loadObject?.pageJSON?.optionalDictionaryForKey("footer"), delegateObject: delegate, moduleList: modules, errorList: nil)
|
||||
MVMCoreUIMoleculeMappingObject.addRequiredModules(forJSON: loadObject?.pageJSON?.optionalDictionaryForKey("moleculeStack"), delegateObject: delegate, moduleList: modules, errorList: nil)
|
||||
return modules.count > 0 ? modules : nil
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user