Skip to content

Instantly share code, notes, and snippets.

@mackoj
Last active May 19, 2022 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mackoj/6499ffea1e1591adc5bc3e3c015761d3 to your computer and use it in GitHub Desktop.
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
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