Simplify a few things of CopySavingButton

- Make saving handler more readable

- Drop unnecessary protocol
This commit is contained in:
Davide De Rosa 2022-05-18 14:07:51 +02:00
parent ddce671c62
commit c88dfc28c4
4 changed files with 4 additions and 20 deletions

View File

@ -25,11 +25,7 @@
import SwiftUI
protocol CopySavingModel: Equatable {
init()
}
struct CopySavingButton<T: CopySavingModel, Label: View>: View {
struct CopySavingButton<T: Equatable, Label: View>: View {
@Binding var original: T
@Binding var copy: T
@ -69,12 +65,9 @@ struct CopySavingButton<T: CopySavingModel, Label: View>: View {
}
private func saveToOriginal() {
defer {
onSave?()
if copy != original {
original = copy
}
guard copy != original else {
return
}
original = copy
onSave?()
}
}

View File

@ -26,9 +26,6 @@
import SwiftUI
import PassepartoutCore
extension Profile.Account: CopySavingModel {
}
struct AccountView: View {
@ObservedObject private var providerManager: ProviderManager

View File

@ -26,9 +26,6 @@
import SwiftUI
import PassepartoutCore
extension Profile.NetworkSettings: CopySavingModel {
}
struct NetworkSettingsView: View {
@ObservedObject private var currentProfile: ObservableProfile

View File

@ -26,9 +26,6 @@
import SwiftUI
import PassepartoutCore
extension Profile.OnDemand: CopySavingModel {
}
struct OnDemandView: View {
@ObservedObject private var productManager: ProductManager