Skip to content

Commit

Permalink
Undo certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Ignition committed Jun 22, 2020
1 parent e0e491c commit d0326b0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions AirPushMac/ViewModels/PushViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ final class PushViewModel: ObservableObject {

@Published var result: PushResult?
@Published var isLoading: Bool = false
@Published var certificate: Certificate?
@Published var certificate: Certificate? {
didSet { undo(\.certificate, oldValue) }
}
@Published var push = PushNotification(deviceToken: "", body: "") {
didSet { registerUndo { $0.push = oldValue } }
didSet { undo(\.push, oldValue) }
}

// MARK: - Actions
Expand All @@ -36,8 +38,8 @@ final class PushViewModel: ObservableObject {

// MARK: - Private

private func registerUndo(handler: @escaping (PushViewModel) -> Void) {
undoManager.registerUndo(withTarget: self, handler: handler)
private func undo<T>(_ keyPath: ReferenceWritableKeyPath<PushViewModel, T>, _ oldValue: T) {
undoManager.registerUndo(withTarget: self, handler: { $0[keyPath: keyPath] = oldValue })
}
}

Expand Down

0 comments on commit d0326b0

Please sign in to comment.