Skip to content

Commit

Permalink
Merge pull request #78 from unsignedapps/disappearing-snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
bok- authored Apr 21, 2021
2 parents b09c276 + 849c9a0 commit 0e8281b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 25 deletions.
12 changes: 4 additions & 8 deletions Sources/Vexil/Snapshots/MutableFlagGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class MutableFlagGroup<Group, Root> where Group: FlagContainer, Root: Fla

// MARK: - Properties

private var group: Group
weak private var snapshot: Snapshot<Root>?
private let group: Group
private let snapshot: Snapshot<Root>


// MARK: - Dynamic Member Lookup
Expand Down Expand Up @@ -45,15 +45,11 @@ public class MutableFlagGroup<Group, Root> where Group: FlagContainer, Root: Fla
///
public subscript<Value> (dynamicMember dynamicMember: KeyPath<Group, Value>) -> Value where Value: FlagValue {
get {
guard let snapshot = self.snapshot else { return self.group[keyPath: dynamicMember] }

return snapshot.lock.withLock {
return self.snapshot.lock.withLock {
self.group[keyPath: dynamicMember]
}
}
set {
guard let snapshot = self.snapshot else { return }

// see Snapshot.swift for how terrible this is
return snapshot.lock.withLock {
_ = self.group[keyPath: dynamicMember]
Expand All @@ -65,7 +61,7 @@ public class MutableFlagGroup<Group, Root> where Group: FlagContainer, Root: Fla

/// Internal initialiser used to create MutableFlagGroups for a given subgroup and snapshot
///
init (group: Group, snapshot: Snapshot<Root>?) {
init (group: Group, snapshot: Snapshot<Root>) {
self.group = group
self.snapshot = snapshot
}
Expand Down
14 changes: 14 additions & 0 deletions Sources/Vexil/Snapshots/Snapshot+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ extension Snapshot: Hashable where RootGroup: Hashable {
hasher.combine(self._rootGroup)
}
}

extension Snapshot: CustomDebugStringConvertible {
public var debugDescription: String {
return "Snapshot<\(String(describing: RootGroup.self))>("
+ Mirror(reflecting: _rootGroup).children
.map { _, value -> String in
(value as? CustomDebugStringConvertible)?.debugDescription
?? (value as? CustomStringConvertible)?.description
?? String(describing: value)
}
.joined(separator: "; ")
+ ")"
}
}
17 changes: 0 additions & 17 deletions Sources/Vexil/Snapshots/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,6 @@ public class Snapshot<RootGroup> where RootGroup: FlagContainer {
}


// MARK: - Debugging

extension Snapshot: CustomDebugStringConvertible {
public var debugDescription: String {
return "Snapshot<\(String(describing: RootGroup.self))>("
+ Mirror(reflecting: _rootGroup).children
.map { _, value -> String in
(value as? CustomDebugStringConvertible)?.debugDescription
?? (value as? CustomStringConvertible)?.description
?? String(describing: value)
}
.joined(separator: "; ")
+ ")"
}
}


#if !os(Linux)

typealias SnapshotValueChanged = PassthroughSubject<Void, Never>
Expand Down

0 comments on commit 0e8281b

Please sign in to comment.