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

Commit

Permalink
Resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPodymov committed Jul 24, 2024
1 parent c215f2c commit 3af551e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Calcium/CalciumApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
//

import ComposableArchitecture
import Resolver
import SwiftUI

@main
struct CalciumApp: App {
init() {
Resolver.register { NativeCalculator() }
.implements(Calculator.self)
}

var body: some Scene {
WindowGroup {
MainScreen(
Expand Down
15 changes: 15 additions & 0 deletions Calcium/Enums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
import BigNumber
import CalciumCommon

protocol Calculator {
func calculateValue(lhs: String, rhs: String, operation: CalciumCommon.Operation) -> String
}

struct NativeCalculator: Calculator {
func calculateValue(lhs: String, rhs: String, operation: CalciumCommon.Operation) -> String {
.init(
operation.calculateValue(
lhs: .init(lhs) ?? .init(),
rhs: .init(rhs) ?? .init()
)
)
}
}

extension CalciumCommon.Digit: CalciumCommon.CalculatorButtonRepresentable {
public var displayingValue: String {
String(value)
Expand Down
9 changes: 5 additions & 4 deletions Calcium/MainReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
import BigNumber
import CalciumCommon
import ComposableArchitecture
import Resolver

enum MainReducerError: Error {
case invalidValues
}

@Reducer
struct MainReducer {
@Injected private var calculator: Calculator

@ObservableState
struct State: Equatable {
var enabled1 = true
Expand Down Expand Up @@ -139,10 +142,8 @@ struct MainReducer {
throw MainReducerError.invalidValues
}
let value = await Task {
operation.calculateValue(
lhs: lhs,
rhs: rhs
)
let result = calculator.calculateValue(lhs: lhs.asString(radix: 10), rhs: rhs.asString(radix: 10), operation: operation)
return BInt(result) ?? .init()
}.value
await send(.calculated(value), animation: .calciumDefault)
}
Expand Down
4 changes: 4 additions & 0 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ packages:
BigNumber:
url: https://github.com/mkrd/Swift-BigInt
version: 2.3.0
Resolver:
url: https://github.com/hmlongco/Resolver
version: 1.5.1
targets:
CalciumApp:
type: application
Expand All @@ -20,6 +23,7 @@ targets:
- framework: CalciumCommon/build/XCFrameworks/release/CalciumCommon.xcframework
- package: ComposableArchitecture
- package: BigNumber
- package: Resolver
info:
path: Calcium/Info.plist
postCompileScripts:
Expand Down

0 comments on commit 3af551e

Please sign in to comment.