-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
robot-divkit
committed
Sep 25, 2023
1 parent
09b9a55
commit 0144edd
Showing
75 changed files
with
3,845 additions
and
190 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
struct DivActionHandlingContext { | ||
let cardId: DivCardID | ||
let expressionResolver: ExpressionResolver | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import Foundation | ||
|
||
final class SetVariableActionHandler { | ||
private let variableStorage: DivVariablesStorage | ||
|
||
init(variableStorage: DivVariablesStorage) { | ||
self.variableStorage = variableStorage | ||
} | ||
|
||
func handle(_ action: DivActionSetVariable, context: DivActionHandlingContext) { | ||
let expressionResolver = context.expressionResolver | ||
guard let variableName = action.resolveVariableName(expressionResolver) else { | ||
return | ||
} | ||
|
||
guard let variableValue = action.value.asVariableValue(expressionResolver: expressionResolver) else { | ||
return | ||
} | ||
|
||
variableStorage.update( | ||
cardId: context.cardId, | ||
name: DivVariableName(rawValue: variableName), | ||
value: variableValue | ||
) | ||
} | ||
} | ||
|
||
|
||
extension DivTypedValue { | ||
fileprivate func asVariableValue( | ||
expressionResolver: ExpressionResolver | ||
) -> DivVariableValue? { | ||
switch self { | ||
case let .arrayValue(value): | ||
if let arrayValue = value.value as? [AnyHashable] { | ||
return .array(arrayValue) | ||
} | ||
return nil | ||
case let .booleanValue(value): | ||
if let boolValue = value.resolveValue(expressionResolver) { | ||
return .bool(boolValue) | ||
} | ||
return nil | ||
case let .colorValue(value): | ||
if let colorValue = value.resolveValue(expressionResolver) { | ||
return .color(colorValue) | ||
} | ||
return nil | ||
case let .dictValue(value): | ||
if let dictValue = value.value as? [String: AnyHashable] { | ||
return .dict(dictValue) | ||
} | ||
return nil | ||
case let .integerValue(value): | ||
if let integerValue = value.resolveValue(expressionResolver) { | ||
return .integer(integerValue) | ||
} | ||
return nil | ||
case let .numberValue(value): | ||
if let numberValue = value.resolveValue(expressionResolver) { | ||
return .number(numberValue) | ||
} | ||
return nil | ||
case let .stringValue(value): | ||
if let stringValue = value.resolveValue(expressionResolver) { | ||
return .string(stringValue) | ||
} | ||
return nil | ||
case let .urlValue(value): | ||
if let urlValue = value.resolveValue(expressionResolver) { | ||
return .url(urlValue) | ||
} | ||
return nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
public enum DivKitInfo { | ||
public static let version = "28.2.0" | ||
public static let version = "28.3.0" | ||
} |
Oops, something went wrong.