-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
88d23c4
commit 173c72d
Showing
10 changed files
with
145 additions
and
75 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import Foundation | ||
|
||
public struct MutateID: Equatable, Hashable, Codable { | ||
public struct MutateID: Comparable, Hashable, Codable, Sendable { | ||
|
||
var value: UInt64 | ||
private var mutationDate: UInt64? | ||
|
||
init() { | ||
value = 0 | ||
init() { | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let date = try UInt64(from: decoder) | ||
mutationDate = date == 0 ? nil : date | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
value = try UInt64(from: decoder) | ||
} | ||
|
||
public func encode(to encoder: Encoder) throws { | ||
try value.encode(to: encoder) | ||
} | ||
public func encode(to encoder: Encoder) throws { | ||
try (mutationDate ?? 0).encode(to: encoder) | ||
} | ||
|
||
mutating func update() { | ||
value = DispatchTime.now().uptimeNanoseconds | ||
public mutating func _update() { | ||
mutationDate = DispatchTime.now().uptimeNanoseconds | ||
} | ||
|
||
public static func < (lhs: MutateID, rhs: MutateID) -> Bool { | ||
lhs.value < rhs.value | ||
(lhs.mutationDate ?? 0) < (rhs.mutationDate ?? 0) | ||
} | ||
|
||
var optional: MutateID? { | ||
mutationDate.map { _ in self } | ||
} | ||
} |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
import Foundation | ||
|
||
public protocol StepsCollection where Steps.RawValue == String { | ||
public protocol StepsCollection { | ||
|
||
associatedtype Steps: RawRepresentable & CaseIterable & Hashable & Codable & Sendable | ||
var selected: Steps { get set } | ||
associatedtype AllSteps: Hashable & Codable & Sendable | ||
var selected: AllSteps { get set } | ||
static var _mutateIDs: [AllSteps: WritableKeyPath<Self, MutateID>] { get } | ||
var _lastMutateID: MutateID? { get } | ||
} | ||
|
||
public protocol OptionalStep: ExpressibleByNilLiteral { | ||
|
||
static var none: Self { get } | ||
} | ||
|
||
extension OptionalStep { | ||
|
||
public init(nilLiteral: ()) { | ||
self = .none | ||
} | ||
} | ||
//extension Optional: CaseIterable where Wrapped: CaseIterable { | ||
// | ||
// public static var allCases: [Wrapped?] { | ||
// [.none] + Wrapped.allCases.map { $0 } | ||
// } | ||
//} | ||
// | ||
//extension Optional: RawRepresentable where Wrapped: RawRepresentable { | ||
// | ||
// public init?(rawValue: Wrapped.RawValue?) { | ||
// switch rawValue { | ||
// case let .some(rawValue): | ||
// guard let wrapped = Wrapped(rawValue: rawValue) else { return nil } | ||
// self = .some(wrapped) | ||
// case .none: | ||
// self = .none | ||
// } | ||
// } | ||
// | ||
// public var rawValue: Wrapped.RawValue? { | ||
// self?.rawValue | ||
// } | ||
//} |
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
Oops, something went wrong.