Last active
May 19, 2022 12:11
-
-
Save mackoj/6499ffea1e1591adc5bc3e3c015761d3 to your computer and use it in GitHub Desktop.
This tool help to make diff on a state when using a TCA app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import CustomDump | |
@propertyWrapper | |
public struct Diff<Value: Equatable>: Equatable { | |
public static func == (lhs: Diff<Value>, rhs: Diff<Value>) -> Bool { | |
lhs.value == rhs.value | |
} | |
private var value: Value | |
private(set) var previous: Value? = nil | |
public init(wrappedValue: Value) { | |
self.value = wrappedValue | |
} | |
public var wrappedValue: Value { | |
get { value } | |
set { | |
previous = value | |
if let output = diff(value, newValue) { print(output) } | |
value = newValue | |
} | |
} | |
public var projectedValue: Self { | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment