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

View File

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

View File

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

View File

@ -10,19 +10,53 @@ import Foundation
import MVMCore
public class RadioButtonModel: MoleculeModelProtocol, FormFieldProtocol {
public static var identifier: String = "radioButton"
public var backgroundColor: Color?
public var state: Bool? = false
public var fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName
public var fieldValue: String?
public var baseValue: JSONValue?
public var baseValue: AnyHashable?
public func formFieldValue() -> JSONValue? {
if let fieldValue = fieldValue {
return JSONValue(stringLiteral: fieldValue)
} else {
return nil
public func formFieldValue() -> AnyHashable? {
return fieldValue
}
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 fieldKey: String?
public var groupName: String? = FormValidator.defaultGroupName
public var baseValue: JSONValue?
public var baseValue: AnyHashable?
private enum CodingKeys: String, CodingKey {
case moleculeName
@ -30,8 +30,8 @@ public class ToggleModel: MoleculeModelProtocol, FormFieldProtocol {
case groupName
}
public func formFieldValue() -> JSONValue? {
return JSONValue(booleanLiteral: state)
public func formFieldValue() -> AnyHashable? {
return state
}
public init(_ state: Bool) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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