moving back to any

This commit is contained in:
Suresh, Kamlesh 2020-03-08 19:14:51 -04:00
parent 22b0b7259f
commit 8df94a2f56
14 changed files with 62 additions and 36 deletions

View File

@ -29,7 +29,7 @@ import Foundation
public var fieldKey: String? public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName public var groupName: String? = FormValidator.defaultGroupName
public var text: String? public var text: String?
public var baseValue: JSONValue? public var baseValue: AnyHashable?
public var isValid: Bool? { public var isValid: Bool? {
didSet { didSet {
@ -61,12 +61,8 @@ import Foundation
case groupName case groupName
} }
public func formFieldValue() -> JSONValue? { public func formFieldValue() -> AnyHashable? {
if let text = text { return text
return JSONValue(stringLiteral: text)
} else {
return nil
}
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -33,7 +33,7 @@ import Foundation
public var fieldKey: String? public var fieldKey: String?
public var fieldValue: JSONValue? public var fieldValue: JSONValue?
public var groupName: String? = FormValidator.defaultGroupName public var groupName: String? = FormValidator.defaultGroupName
public var baseValue: JSONValue? public var baseValue: AnyHashable?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Keys // MARK: - Keys
@ -61,8 +61,8 @@ import Foundation
init(isChecked: Bool = false) {} init(isChecked: Bool = false) {}
public func formFieldValue() -> JSONValue? { public func formFieldValue() -> AnyHashable? {
return JSONValue(booleanLiteral: isChecked) return isChecked
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -83,11 +83,8 @@ import UIKit
return radioModel?.fieldKey return radioModel?.fieldKey
} }
public func formFieldValue() -> JSONValue? { public func formFieldValue() -> AnyHashable? {
if let fieldValue = radioModel?.fieldValue { return radioModel?.fieldValue
return JSONValue(stringLiteral: fieldValue)
}
return nil
} }
// MARK: - MVMViewProtocol // MARK: - MVMViewProtocol

View File

@ -10,19 +10,53 @@ import Foundation
import MVMCore import MVMCore
public class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol { public class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
public static var identifier: String = "radioButton" public static var identifier: String = "radioButton"
public var backgroundColor: Color? public var backgroundColor: Color?
public var state: Bool? = false public var state: Bool? = false
public var fieldKey: String? public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName public var groupName: String? = FormValidator.defaultGroupName
public var fieldValue: String? public var fieldValue: String?
public var baseValue: JSONValue? public var baseValue: AnyHashable?
public func formFieldValue() -> JSONValue? { public func formFieldValue() -> AnyHashable? {
if let fieldValue = fieldValue { return fieldValue
return JSONValue(stringLiteral: fieldValue) }
} else {
return nil private enum CodingKeys: String, CodingKey {
case moleculeName
case state
case backgroundColor
case fieldKey
case groupName
case fieldValue
}
public init(_ state: Bool) {
self.state = state
}
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
if let state = try typeContainer.decodeIfPresent(Bool.self, forKey: .state) {
self.state = state
}
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
fieldValue = try typeContainer.decodeIfPresent(String.self, forKey: .fieldValue)
if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) {
self.groupName = groupName
} }
} }
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(state, forKey: .state)
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
try container.encodeIfPresent(fieldValue, forKey: .fieldValue)
try container.encodeIfPresent(groupName, forKey: .groupName)
}
} }

View File

@ -17,7 +17,7 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
public var alternateAction: ActionModelProtocol? public var alternateAction: ActionModelProtocol?
public var fieldKey: String? public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName public var groupName: String? = FormValidator.defaultGroupName
public var baseValue: JSONValue? public var baseValue: AnyHashable?
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
@ -30,8 +30,8 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
case groupName case groupName
} }
public func formFieldValue() -> JSONValue? { public func formFieldValue() -> AnyHashable? {
return JSONValue(booleanLiteral: state) return state
} }
public init(_ state: Bool) { public init(_ state: Bool) {

View File

@ -11,12 +11,12 @@ import Foundation
public protocol FormFieldProtocol: FormItemProtocol { public protocol FormFieldProtocol: FormItemProtocol {
var fieldKey: String? { get set } var fieldKey: String? { get set }
var baseValue: JSONValue? { get set } var baseValue: AnyHashable? { get set }
func formFieldValue() -> JSONValue? func formFieldValue() -> AnyHashable?
} }
extension FormFieldProtocol { extension FormFieldProtocol {
var baseValue: JSONValue? { var baseValue: AnyHashable? {
return nil return nil
} }
} }

View File

@ -10,7 +10,6 @@ import Foundation
open class FormGroupRule: Codable { open class FormGroupRule: Codable {
// public static var identifier: String = "formRule"
var groupName: String var groupName: String
var rules: [RulesProtocol] var rules: [RulesProtocol]

View File

@ -11,7 +11,7 @@ import Foundation
public class RuleAllValueChangedModel: RulesProtocol { public class RuleAllValueChangedModel: RulesProtocol {
public static var identifier: String = "allValueChanged" public static var identifier: String = "allValueChanged"
public var ruleType: String = RuleAllValueChangedModel.identifier public var type: String = RuleAllValueChangedModel.identifier
public var fields: [String] public var fields: [String]
public func isValid(_ formField: FormFieldProtocol) -> Bool { public func isValid(_ formField: FormFieldProtocol) -> Bool {

View File

@ -11,7 +11,7 @@ import Foundation
public class RuleAnyValueChangedModel: RulesProtocol { public class RuleAnyValueChangedModel: RulesProtocol {
public static var identifier: String = "anyValueChanged" public static var identifier: String = "anyValueChanged"
public var ruleType: String = RuleAnyValueChangedModel.identifier public var type: String = RuleAnyValueChangedModel.identifier
public var fields: [String] public var fields: [String]
public func isValid(_ formField: FormFieldProtocol) -> Bool { public func isValid(_ formField: FormFieldProtocol) -> Bool {

View File

@ -11,7 +11,7 @@ import Foundation
public class RuleEqualsModel: RulesProtocol { public class RuleEqualsModel: RulesProtocol {
public static var identifier: String = "equals" public static var identifier: String = "equals"
public var ruleType: String = RuleEqualsModel.identifier public var type: String = RuleEqualsModel.identifier
public var fields: [String] public var fields: [String]
public func isValid(_ formField: FormFieldProtocol) -> Bool { public func isValid(_ formField: FormFieldProtocol) -> Bool {

View File

@ -10,7 +10,7 @@ import Foundation
public class RuleRegexModel: RulesProtocol { public class RuleRegexModel: RulesProtocol {
public static var identifier: String = "regex" public static var identifier: String = "regex"
public var ruleType: String = RuleRegexModel.identifier public var type: String = RuleRegexModel.identifier
public var fields: [String] public var fields: [String]
public func isValid(_ formField: FormFieldProtocol) -> Bool { public func isValid(_ formField: FormFieldProtocol) -> Bool {

View File

@ -12,7 +12,7 @@ import Foundation
public class RuleRequiredModel: RulesProtocol { public class RuleRequiredModel: RulesProtocol {
public static var identifier: String = "required" public static var identifier: String = "required"
public var ruleType: String = RuleRequiredModel.identifier public var type: String = RuleRequiredModel.identifier
public var fields: [String] public var fields: [String]
public func isValid(_ formField: FormFieldProtocol) -> Bool { public func isValid(_ formField: FormFieldProtocol) -> Bool {

View File

@ -14,7 +14,7 @@ public enum RulesCodingKey: String, CodingKey {
} }
public protocol RulesProtocol: ModelProtocol { public protocol RulesProtocol: ModelProtocol {
var ruleType: String { get set } var type: String { get set }
var fields: [String] { get set } var fields: [String] { get set }
func isValid(_ formValidator: FormValidator) -> Bool func isValid(_ formValidator: FormValidator) -> Bool
func isValid(_ formField: FormFieldProtocol) -> Bool func isValid(_ formField: FormFieldProtocol) -> Bool

View File

@ -16,7 +16,7 @@ import UIKit
public var groupName: String? = FormValidator.defaultGroupName public var groupName: String? = FormValidator.defaultGroupName
private var selectedRadioButton: RadioButton? private var selectedRadioButton: RadioButton?
private var fieldGroupName: String? private var fieldGroupName: String?
public var baseValue: JSONValue? public var baseValue: AnyHashable?
init(_ fieldKey: String?) { init(_ fieldKey: String?) {
self.fieldKey = fieldKey self.fieldKey = fieldKey
@ -47,7 +47,7 @@ extension RadioButtonSelectionHelper {
return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName
} }
public func formFieldValue() -> JSONValue? { public func formFieldValue() -> AnyHashable? {
return selectedRadioButton?.formFieldValue() return selectedRadioButton?.formFieldValue()
} }
} }