Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fix: multiple expression not working when observing due to cache
Browse files Browse the repository at this point in the history
  • Loading branch information
theffc committed Sep 22, 2020
1 parent 1cdcf29 commit 604319f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ final class UIViewContextTests: XCTestCase {
leaf.contextMap = ["leaf": contextObservableLeaf]

let singleExpression = SingleExpression.value(.binding(.init(context: "context", path: .init(nodes: [.key("a")]))))
let leafExpression = SingleExpression.value(.binding(.init(context: "leaf", path: .init(nodes: [.index(0)]))))
let exp = ContextExpression.single(singleExpression)
let multipleExpression = ContextExpression.multiple(.init(nodes: [.string("exp: "), .expression(singleExpression)]))
let multipleExpression = ContextExpression.multiple(.init(nodes: [.string("exp: "), .expression(singleExpression), .string(", leaf: "), .expression(leafExpression)]))

leaf.configBinding(for: exp) {
leaf.text = $0
Expand All @@ -131,11 +132,11 @@ final class UIViewContextTests: XCTestCase {

contextObservableRoot.value = Context(id: "context", value: ["a": "updated", "b": "2"])
XCTAssertEqual(leaf.text, "updated")
XCTAssertEqual(leaf.placeholder, "exp: updated")
XCTAssertEqual(leaf.placeholder, "exp: updated, leaf: test")

contextObservableRoot.value = Context(id: "context", value: ["a": 2])
XCTAssertEqual(leaf.text, "2")
XCTAssertEqual(leaf.placeholder, "exp: 2")
XCTAssertEqual(leaf.placeholder, "exp: 2, leaf: test")
}

func testConfigBindingShouldNotRetainTheView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,11 @@ extension UIView {
// expression last value cache is used only for multiple expressions binding
private func evaluateWithCache<T: Decodable>(for expression: SingleExpression, contextId: String? = nil) -> T? {
switch expression {
case let .value(.binding(binding)):
if contextId == nil || contextId == binding.context {
return evaluate(for: expression)
} else {
return transform(expressionLastValueMap[expression.rawValue] ?? .empty)
}
// TODO: expression caching is not working with multiple expressions, so we won't use cache for now, until we
// we have a better solution to this problem
case .value(.binding):
return evaluate(for: expression)

case let .value(.literal(literal)):
return transform(literal.evaluate())
case let .operation(operation):
Expand Down

0 comments on commit 604319f

Please sign in to comment.