Files
divkit/client/ios/DivKit/Actions/DictSetValueActionHandler.swift
pkurchatov 10a5789539 Local variables
94156d00b5e15f7aa05d65af81601ff2b84333a7
2024-06-28 12:14:17 +03:00

28 lines
839 B
Swift

import Foundation
final class DictSetValueActionHandler {
func handle(_ action: DivActionDictSetValue, context: DivActionHandlingContext) {
let expressionResolver = context.expressionResolver
guard let variableName = action.resolveVariableName(expressionResolver),
let key = action.resolveKey(expressionResolver),
var dict: DivDictionary = context.variablesStorage.getVariableValue(
path: context.path,
name: DivVariableName(rawValue: variableName)
) else {
return
}
if let value = action.value?.resolve(expressionResolver) {
dict[key] = value
} else {
dict.removeValue(forKey: key)
}
context.variablesStorage.update(
path: context.path,
name: DivVariableName(rawValue: variableName),
value: .dict(dict)
)
}
}