diff --git a/Calcium/CalciumApp.swift b/Calcium/CalciumApp.swift index f7f117b..6ddc9b7 100644 --- a/Calcium/CalciumApp.swift +++ b/Calcium/CalciumApp.swift @@ -14,7 +14,7 @@ import SwiftUI @main struct CalciumApp: App { init() { - Resolver.register { KMMCalculator() } + Resolver.register { NativeCalculator() } .implements(Calculator.self) } diff --git a/Calcium/CalculatorClient.swift b/Calcium/CalculatorClient.swift new file mode 100644 index 0000000..fc09bec --- /dev/null +++ b/Calcium/CalculatorClient.swift @@ -0,0 +1,45 @@ +// +// CalculatorClient.swift +// Calcium +// +// Created by Roman Podymov on 11/08/2024. +// Copyright © 2024 Calcium. All rights reserved. +// + +import CalciumCommon +import ComposableArchitecture +import Resolver + +@DependencyClient +struct CalculatorClient { + var calculateValue: (String, String, CalciumCommon.Operation) -> String = { _, _, _ in "" } +} + +extension DependencyValues { + var calculator: CalculatorClient { + get { self[CalculatorClient.self] } + set { self[CalculatorClient.self] = newValue } + } +} + +extension CalculatorClient: DependencyKey { + static let liveValue = CalculatorClient( + calculateValue: { + @Injected var calculator: Calculator + + return calculator.calculateValue(lhs: $0, rhs: $1, operation: $2) + } + ) +} + +extension CalculatorClient: TestDependencyKey { + static let previewValue = { + @Injected var calculator: Calculator + + return Self(calculateValue: { + NativeCalculator().calculateValue(lhs: $0, rhs: $1, operation: $2) + }) + }() + + static let testValue = previewValue +} diff --git a/Calcium/MainReducer.swift b/Calcium/MainReducer.swift index b4a76b8..0ba56ee 100644 --- a/Calcium/MainReducer.swift +++ b/Calcium/MainReducer.swift @@ -9,7 +9,6 @@ import BigNumber import CalciumCommon import ComposableArchitecture -import Resolver enum MainReducerError: Error { case invalidValues @@ -17,7 +16,7 @@ enum MainReducerError: Error { @Reducer struct MainReducer { - @Injected private var calculator: Calculator + @Dependency(\.calculator) var calculator @ObservableState struct State: Equatable { @@ -142,7 +141,11 @@ struct MainReducer { throw MainReducerError.invalidValues } let value = await Task { - let result = calculator.calculateValue(lhs: lhs.asString(radix: 10), rhs: rhs.asString(radix: 10), operation: operation) + let result = calculator.calculateValue( + lhs.asString(radix: 10), + rhs.asString(radix: 10), + operation + ) return BInt(result) ?? .init() }.value await send(.calculated(value), animation: .calciumDefault) diff --git a/build.gradle.kts b/build.gradle.kts index 51fe1b1..73ec8ae 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,3 @@ plugins { - kotlin("multiplatform").version("2.0.20-Beta2").apply(false) + kotlin("multiplatform").version("2.0.20-RC").apply(false) }