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

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPodymov committed Jun 27, 2024
1 parent 1405a5b commit b3c4b33
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
52 changes: 22 additions & 30 deletions Calcium/MainReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct MainReducer {
var enabledMinus = true
var enabledMultiply = true
var enabledDivide = true
var enabledFactorial = true

var leftValue: BInt?
var displayingText = ""
Expand All @@ -51,27 +52,32 @@ struct MainReducer {
switch calculatorButton {
case let .operation(operation):
if operation.isUnary {
enabled0 = false
enabled1 = false
enabled2 = false
enabled3 = false
enabled4 = false
enabled5 = false
enabled6 = false
enabled7 = false
enabled8 = false
enabled9 = false

enabledPlus = false
enabledMinus = false
enabledMultiply = false
enabledDivide = false
set(enabled: false)
}
default:
break
}
}

mutating func set(enabled: Bool) {
enabled0 = enabled
enabled1 = enabled
enabled2 = enabled
enabled3 = enabled
enabled4 = enabled
enabled5 = enabled
enabled6 = enabled
enabled7 = enabled
enabled8 = enabled
enabled9 = enabled

enabledPlus = enabled
enabledMinus = enabled
enabledMultiply = enabled
enabledDivide = enabled
enabledFactorial = enabled
}

mutating func onButtonPressed(calculatorButton: CalculatorButton) -> Operation? {
switch calculatorButton {
case let .digit(value):
Expand Down Expand Up @@ -126,21 +132,7 @@ struct MainReducer {
state.displayingText = String(value)
state.latestOperationButton = .operation(.equals)

state.enabled0 = true
state.enabled1 = true
state.enabled2 = true
state.enabled3 = true
state.enabled4 = true
state.enabled5 = true
state.enabled6 = true
state.enabled7 = true
state.enabled8 = true
state.enabled9 = true

state.enabledPlus = true
state.enabledMinus = true
state.enabledMultiply = true
state.enabledDivide = true
state.set(enabled: true)

return .none
}
Expand Down
2 changes: 1 addition & 1 deletion Calcium/MainScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct MainScreen: View {

HStack {
view(for: .digit(.zero), enabled: store.state.enabled0)
view(for: .operation(.factorial))
view(for: .operation(.factorial), enabled: store.state.enabledFactorial)
view(for: .clear)
}

Expand Down

0 comments on commit b3c4b33

Please sign in to comment.