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

Commit

Permalink
Resolver fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPodymov committed Nov 3, 2024
1 parent 1269b20 commit 51577d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Calcium/CalciumApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

import CalciumCommon
import ComposableArchitecture

import Resolver
import SwiftUI

@main
struct CalciumApp: App {
init() {
// Resolver.register { NativeCalculator() }
// .implements(Calculator.self)
Resolver.register(Calculator.self, name: .name(fromString: "calculator")) {
NativeCalculator()
}
}

var body: some Scene {
Expand Down
23 changes: 13 additions & 10 deletions Calcium/CalculatorClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,27 @@

import CalciumCommon
import ComposableArchitecture

import Resolver
@preconcurrency import Resolver

@DependencyClient
struct CalculatorClient: Sendable, DependencyKey, TestDependencyKey {
var calculateValue: @Sendable (String, String, CalciumCommon.Operation) -> String = { _, _, _ in "" }

static let previewValue = // @Injected var calculator: Calculator

Self(calculateValue: {
NativeCalculator().calculateValue(lhs: $0, rhs: $1, operation: $2)
})
static let previewValue = CalculatorClient(
calculateValue: {
Resolver.resolve(
Calculator.self,
name: .name(fromString: "calculator")
).calculateValue(lhs: $0, rhs: $1, operation: $2)
}
)

static let liveValue = CalculatorClient(
calculateValue: {
// @Injected var calculator: Calculator

NativeCalculator().calculateValue(lhs: $0, rhs: $1, operation: $2)
Resolver.resolve(
Calculator.self,
name: .name(fromString: "calculator")
).calculateValue(lhs: $0, rhs: $1, operation: $2)
}
)

Expand Down
2 changes: 1 addition & 1 deletion Calcium/MainReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ struct MainReducer {
guard let lhs, let rhs else {
throw MainReducerError.invalidValues
}
let value = await Task {
let value = await Task { @MainActor in
let result = calculator.calculateValue(
lhs.asString(radix: 10),
rhs.asString(radix: 10),
Expand Down

0 comments on commit 51577d9

Please sign in to comment.