Skip to content

Commit

Permalink
Releasing v7.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Judo Release Bot 🤖 authored and seanrucker committed Mar 28, 2024
1 parent c511d77 commit 03f39be
Show file tree
Hide file tree
Showing 69 changed files with 655 additions and 786 deletions.
4 changes: 2 additions & 2 deletions Demo/JudoDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 7.0;
MARKETING_VERSION = 7.0.3;
PRODUCT_BUNDLE_IDENTIFIER = app.judo.Demo;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down Expand Up @@ -332,7 +332,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 7.0;
MARKETING_VERSION = 7.0.3;
PRODUCT_BUNDLE_IDENTIFIER = app.judo.Demo;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down
2 changes: 1 addition & 1 deletion Sources/JudoDocument/Nodes/DocumentNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public struct DocumentNode: Node {
self.userData = userData
}

public var allNodes: [Any] {
public var allNodes: [Node] {
children + deletedNodes
}

Expand Down
28 changes: 14 additions & 14 deletions Sources/JudoDocument/Value Types/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public struct Expression<T: Codable & Hashable & CustomStringConvertible>: Hasha
}

/// Evaluates an expression using a specified properties and functions.
func evaluate(propertyValues: [String: PropertyValue], data: Any?, functions: [ExpressionFunction] = []) throws -> T? {
func evaluate(propertyValues: [String: PropertyValue], data: Any?, functions: [JudoExpressionFunction] = []) throws -> T? {
var variables = propertyValues.compactMap { element in
switch element.value {
case .number(let doubleValue):
return ExpressionVariable(element.key, value: doubleValue)
return JudoExpressionVariable(element.key, value: doubleValue)
case .text(let stringValue):
return ExpressionVariable(element.key, value: stringValue)
return JudoExpressionVariable(element.key, value: stringValue)
case .boolean(let boolValue):
return ExpressionVariable(element.key, value: boolValue)
return JudoExpressionVariable(element.key, value: boolValue)
case .computed(let computedValue):

// replace expression with resulting value
Expand All @@ -53,12 +53,12 @@ public struct Expression<T: Codable & Hashable & CustomStringConvertible>: Hasha

switch computedValue {
case .number(let expression):
return try? ExpressionVariable(element.key, value: expression.evaluate(propertyValues: propertyValues, data: data, functions: functions))
return try? JudoExpressionVariable(element.key, value: expression.evaluate(propertyValues: propertyValues, data: data, functions: functions))
case .text(let expression):
return try? ExpressionVariable(element.key, value: expression.evaluate(propertyValues: propertyValues, data: data, functions: functions))
return try? JudoExpressionVariable(element.key, value: expression.evaluate(propertyValues: propertyValues, data: data, functions: functions))
case .boolean(let expression):
if let evaluatedValue = try? expression.evaluate(propertyValues: propertyValues, data: data, functions: functions) {
return ExpressionVariable(element.key, value: evaluatedValue)
return JudoExpressionVariable(element.key, value: evaluatedValue)
} else {
return nil
}
Expand All @@ -76,18 +76,18 @@ public struct Expression<T: Codable & Hashable & CustomStringConvertible>: Hasha
}

/// Evaluates an expression using a specified variables and functions.
func evaluate(variables: [JudoExpressions.ExpressionVariable] = [], functions: [ExpressionFunction] = []) throws -> T? {
try Interpreter(variables: variables, functions: functions).interpret(expression) as? T
func evaluate(variables: [JudoExpressions.JudoExpressionVariable] = [], functions: [JudoExpressionFunction] = []) throws -> T? {
try JudoInterpreter(variables: variables, functions: functions).interpret(expression) as? T
}

private func dataVariables(value: Any, keyPath: [String]) -> [ExpressionVariable]? {
private func dataVariables(value: Any, keyPath: [String]) -> [JudoExpressionVariable]? {
switch value {
case let number as Double:
return [ExpressionVariable(keyPath.joined(separator: "\u{B7}"), value: number)]
return [JudoExpressionVariable(keyPath.joined(separator: "\u{B7}"), value: number)]
case let string as String:
return [ExpressionVariable(keyPath.joined(separator: "\u{B7}"), value: string)]
return [JudoExpressionVariable(keyPath.joined(separator: "\u{B7}"), value: string)]
case let dictionary as [String: Any]:
return dictionary.reduce(into: [ExpressionVariable]()) { partialResult, element in
return dictionary.reduce(into: [JudoExpressionVariable]()) { partialResult, element in
let keyPath = keyPath + [element.key]
partialResult += dataVariables(value: element.value, keyPath: keyPath) ?? []
}
Expand Down Expand Up @@ -149,7 +149,7 @@ extension Expression<Bool>: ExpressibleByBooleanLiteral {

/// Library of standard functions
private let standardLibrary = [
ExpressionFunction("formatted", closure: { caller, _ in
JudoExpressionFunction("formatted", closure: { caller, _ in
guard let value = caller as? Double else {
return caller
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/JudoExpressions/Interpreter/Callable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

protocol Callable {
func call(_ interpreter: Interpreter, caller: Any?, _ args: [Any?]) throws -> Any?
func call(_ interpreter: JudoInterpreter, caller: Any?, _ args: [Any?]) throws -> Any?
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

public struct ExpressionFunction: Callable {
public struct JudoExpressionFunction: Callable {
let selector: String
let closure: (_ caller: Any?, _ arguments: [Any?]) throws -> Any?

Expand All @@ -22,7 +22,7 @@ public struct ExpressionFunction: Callable {
self.closure = closure
}

func call(_ interpreter: Interpreter, caller: Any?, _ args: [Any?]) throws -> Any? {
func call(_ interpreter: JudoInterpreter, caller: Any?, _ args: [Any?]) throws -> Any? {
try closure(caller, args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

public struct ExpressionVariable {
public struct JudoExpressionVariable {
public let identifier: String
let value: Any?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ private var numberFormatter: NumberFormatter = {
return formatter
}()

public class Interpreter: ExpressionVisitor, StatementVisitor {
public class JudoInterpreter: ExpressionVisitor, StatementVisitor {

/// global variables
private let globalVariables: [ExpressionVariable]
private let globalFunctions: [ExpressionFunction]
private let globalVariables: [JudoExpressionVariable]
private let globalFunctions: [JudoExpressionFunction]

public init(variables: [ExpressionVariable] = [], functions: [ExpressionFunction] = []) {
public init(variables: [JudoExpressionVariable] = [], functions: [JudoExpressionFunction] = []) {
self.globalVariables = variables
self.globalFunctions = standardLibrary + functions
}
Expand Down Expand Up @@ -88,7 +88,7 @@ public class Interpreter: ExpressionVisitor, StatementVisitor {
/// Call function with callee instance as caller
/// Wrap original function in a function (method) that
/// set instance (caller) as a caller
return ExpressionFunction(methodName) { _, arguments in
return JudoExpressionFunction(methodName) { _, arguments in
try function.call(self, caller: caller, arguments)
}
}
Expand Down Expand Up @@ -276,13 +276,13 @@ private extension Equatable {
}
}

private extension Array<ExpressionVariable> {
private extension Array<JudoExpressionVariable> {
subscript<S: StringProtocol>(_ identifier: S) -> Any? {
first(where: { $0.identifier == identifier })?.value
}
}

private extension Array<ExpressionFunction> {
private extension Array<JudoExpressionFunction> {
subscript<S: StringProtocol>(_ identifier: S) -> Element? {
first(where: { $0.selector == identifier })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation

/// Library of standard functions
let standardLibrary = [
ExpressionFunction("formatted", closure: { caller, _ in
JudoExpressionFunction("formatted", closure: { caller, _ in
guard let value = caller as? Double else {
return caller
}
Expand Down
48 changes: 48 additions & 0 deletions Sources/JudoRenderer/Environment/ComponentBindings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2023-present, Rover Labs, Inc. All rights reserved.
// You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
// copy, modify, and distribute this software in source code or binary form for use
// in connection with the web services and APIs provided by Rover.
//
// This copyright notice shall be included in all copies or substantial portions of
// the software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import JudoDocument
import SwiftUI

typealias ComponentBindings = [String: Binding<Any>]

extension ComponentBindings {
var propertyValues: [String: PropertyValue] {
reduce(into: [:]) { partialResult, element in
switch element.value.wrappedValue {
case let value as String:
partialResult[element.key] = .text(value)
case let value as Double:
partialResult[element.key] = .number(value)
case let value as Bool:
partialResult[element.key] = .boolean(value)
case let value as ImageReference:
partialResult[element.key] = .image(value)
case let value as UUID:
partialResult[element.key] = .component(value)
case let value as Video:
partialResult[element.key] = .video(value)
case let value as Expression<String>:
partialResult[element.key] = .computed(.text(value))
case let value as Expression<Double>:
partialResult[element.key] = .computed(.number(value))
case let value as Expression<Bool>:
partialResult[element.key] = .computed(.boolean(value))
default:
break
}
}
}
}
Loading

0 comments on commit 03f39be

Please sign in to comment.