mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
28 lines
839 B
Swift
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)
|
|
)
|
|
}
|
|
}
|