mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
78 lines
3.5 KiB
Swift
78 lines
3.5 KiB
Swift
// Generated code. Do not modify.
|
|
|
|
import Foundation
|
|
import Serialization
|
|
import VGSL
|
|
|
|
public final class DivLayoutProviderTemplate: TemplateValue, Sendable {
|
|
public let heightVariableName: Field<String>?
|
|
public let widthVariableName: Field<String>?
|
|
|
|
public convenience init(dictionary: [String: Any], templateToType: [TemplateName: String]) throws {
|
|
self.init(
|
|
heightVariableName: dictionary.getOptionalField("height_variable_name"),
|
|
widthVariableName: dictionary.getOptionalField("width_variable_name")
|
|
)
|
|
}
|
|
|
|
init(
|
|
heightVariableName: Field<String>? = nil,
|
|
widthVariableName: Field<String>? = nil
|
|
) {
|
|
self.heightVariableName = heightVariableName
|
|
self.widthVariableName = widthVariableName
|
|
}
|
|
|
|
private static func resolveOnlyLinks(context: TemplatesContext, parent: DivLayoutProviderTemplate?) -> DeserializationResult<DivLayoutProvider> {
|
|
let heightVariableNameValue = parent?.heightVariableName?.resolveOptionalValue(context: context) ?? .noValue
|
|
let widthVariableNameValue = parent?.widthVariableName?.resolveOptionalValue(context: context) ?? .noValue
|
|
let errors = mergeErrors(
|
|
heightVariableNameValue.errorsOrWarnings?.map { .nestedObjectError(field: "height_variable_name", error: $0) },
|
|
widthVariableNameValue.errorsOrWarnings?.map { .nestedObjectError(field: "width_variable_name", error: $0) }
|
|
)
|
|
let result = DivLayoutProvider(
|
|
heightVariableName: heightVariableNameValue.value,
|
|
widthVariableName: widthVariableNameValue.value
|
|
)
|
|
return errors.isEmpty ? .success(result) : .partialSuccess(result, warnings: NonEmptyArray(errors)!)
|
|
}
|
|
|
|
public static func resolveValue(context: TemplatesContext, parent: DivLayoutProviderTemplate?, useOnlyLinks: Bool) -> DeserializationResult<DivLayoutProvider> {
|
|
if useOnlyLinks {
|
|
return resolveOnlyLinks(context: context, parent: parent)
|
|
}
|
|
var heightVariableNameValue: DeserializationResult<String> = parent?.heightVariableName?.value() ?? .noValue
|
|
var widthVariableNameValue: DeserializationResult<String> = parent?.widthVariableName?.value() ?? .noValue
|
|
context.templateData.forEach { key, __dictValue in
|
|
switch key {
|
|
case "height_variable_name":
|
|
heightVariableNameValue = deserialize(__dictValue).merged(with: heightVariableNameValue)
|
|
case "width_variable_name":
|
|
widthVariableNameValue = deserialize(__dictValue).merged(with: widthVariableNameValue)
|
|
case parent?.heightVariableName?.link:
|
|
heightVariableNameValue = heightVariableNameValue.merged(with: { deserialize(__dictValue) })
|
|
case parent?.widthVariableName?.link:
|
|
widthVariableNameValue = widthVariableNameValue.merged(with: { deserialize(__dictValue) })
|
|
default: break
|
|
}
|
|
}
|
|
let errors = mergeErrors(
|
|
heightVariableNameValue.errorsOrWarnings?.map { .nestedObjectError(field: "height_variable_name", error: $0) },
|
|
widthVariableNameValue.errorsOrWarnings?.map { .nestedObjectError(field: "width_variable_name", error: $0) }
|
|
)
|
|
let result = DivLayoutProvider(
|
|
heightVariableName: heightVariableNameValue.value,
|
|
widthVariableName: widthVariableNameValue.value
|
|
)
|
|
return errors.isEmpty ? .success(result) : .partialSuccess(result, warnings: NonEmptyArray(errors)!)
|
|
}
|
|
|
|
private func mergedWithParent(templates: [TemplateName: Any]) throws -> DivLayoutProviderTemplate {
|
|
return self
|
|
}
|
|
|
|
public func resolveParent(templates: [TemplateName: Any]) throws -> DivLayoutProviderTemplate {
|
|
return try mergedWithParent(templates: templates)
|
|
}
|
|
}
|