updating specific model class change for Modal template

This commit is contained in:
“subrra7” 2020-07-16 21:26:10 +05:30
parent 0ee938cf57
commit 66b0370574
5 changed files with 41 additions and 34 deletions

View File

@ -23,24 +23,24 @@ import Foundation
// MARK: - Keys
//--------------------------------------------------
// private enum CodingKeys: String, CodingKey {
// case closeAction
// }
//
// //--------------------------------------------------
// // MARK: - Codec
// //--------------------------------------------------
//
// required public init(from decoder: Decoder) throws {
// let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
// closeAction = try typeContainer.decodeModelIfPresent(codingKey: .closeAction)
// try super.init(from: decoder)
// }
//
// open override func encode(to encoder: Encoder) throws {
// try super.encode(to: encoder)
// var container = encoder.container(keyedBy: CodingKeys.self)
// try container.encodeModelIfPresent(closeAction, forKey: .closeAction)
// }
private enum CodingKeys: String, CodingKey {
case closeAction
}
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
closeAction = try typeContainer.decodeModelIfPresent(codingKey: .closeAction)
try super.init(from: decoder)
}
open override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeModelIfPresent(closeAction, forKey: .closeAction)
}
}

View File

@ -20,6 +20,11 @@ open class ModalMoleculeListTemplate: MoleculeListTemplate {
// MARK: - Lifecycle
//--------------------------------------------------
// For subclassing the model.
open override func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> ModalListPageTemplateModel {
return try decoder.decode(ModalListPageTemplateModel.self, from: data)
}
override open func handleNewData() {
super.handleNewData()

View File

@ -10,17 +10,23 @@ import UIKit
open class ModalMoleculeStackTemplate: MoleculeStackTemplate {
// For subclassing the model.
open override func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> ModalStackPageTemplateModel {
return try decoder.decode(ModalStackPageTemplateModel.self, from: data)
}
override open func handleNewData() {
super.handleNewData()
_ = MVMCoreUICommonViewsUtility.addCloseButton(to: view, action: {[weak self] _ in
guard let self = self else {
return
}
// guard let actionMap = self.templateModel?.closeAction else {
// MVMCoreActionHandler.shared()?.handleAction(with: ActionBackModel().toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar)
// return
// }
// MVMCoreActionHandler.shared()?.handleAction(with: actionMap.toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar)
guard let model = self.templateModel as? ModalStackPageTemplateModel, let actionMap = model.closeAction else {
MVMCoreActionHandler.shared()?.handleAction(with: ActionBackModel().toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar)
return
}
MVMCoreActionHandler.shared()?.handleAction(with: actionMap.toJSON(), additionalData: nil, delegateObject: self.delegateObjectIVar)
})
}
}

View File

@ -8,26 +8,18 @@
import Foundation
@objcMembers public class ModalStackPageTemplateModel: ThreeLayerModelBase {
@objcMembers public class ModalStackPageTemplateModel: StackPageTemplateModel {
public override class var identifier: String {
return "modalStack"
}
public var moleculeStack: StackModel
public var closeAction: ActionModelProtocol?
public init(pageType: String, moleculeStack: StackModel) {
self.moleculeStack = moleculeStack
super.init(pageType: pageType)
}
private enum CodingKeys: String, CodingKey {
case stack
case closeAction
}
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
moleculeStack = try typeContainer.decode(StackModel.self, forKey: .stack)
closeAction = try typeContainer.decodeModelIfPresent(codingKey: .closeAction)
try super.init(from: decoder)
}
@ -35,7 +27,6 @@ import Foundation
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(moleculeStack, forKey: .stack)
try container.encodeModelIfPresent(closeAction, forKey: .closeAction)
}
}

View File

@ -17,6 +17,11 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol {
bottomViewOutsideOfScroll = templateModel?.anchorFooter ?? false
super.handleNewData()
}
// For subclassing the model.
open func decodeTemplate(using decoder: JSONDecoder, from data: Data) throws -> StackPageTemplateModel {
return try decoder.decode(StackPageTemplateModel.self, from: data)
}
open override func parsePageJSON() throws {
try parseTemplate(json: loadObject?.pageJSON)