Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Sources/Atoms/Core/AtomCache.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
@MainActor
internal protocol AtomCacheProtocol: CustomStringConvertible {
internal protocol AtomCacheProtocol {
associatedtype Node: Atom

var atom: Node { get set }
var value: Node.Loader.Value { get set }
}

internal extension AtomCacheProtocol {
internal struct AtomCache<Node: Atom>: AtomCacheProtocol, CustomStringConvertible {
var atom: Node
var value: Node.Loader.Value

var description: String {
"\(value)"
}
}

internal struct AtomCache<Node: Atom>: AtomCacheProtocol {
var atom: Node
var value: Node.Loader.Value
}
6 changes: 3 additions & 3 deletions Sources/Atoms/Core/AtomKey.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
internal struct AtomKey: Hashable {
internal struct AtomKey: Hashable, CustomStringConvertible {
private let key: AnyHashable
private let type: ObjectIdentifier
private let scopeKey: ScopeKey?
private let anyAtomType: Any.Type

var debugLabel: String {
var description: String {
let atomLabel = String(describing: anyAtomType)

if let scopeKey {
return atomLabel + "-scoped:\(scopeKey.debugLabel)"
return atomLabel + "-scoped:\(scopeKey)"
}
else {
return atomLabel
Expand Down
5 changes: 3 additions & 2 deletions Sources/Atoms/Core/ScopeKey.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
@usableFromInline
internal struct ScopeKey: Hashable {
internal struct ScopeKey: Hashable, CustomStringConvertible {
final class Token {}

private let identifier: ObjectIdentifier

var debugLabel: String {
@usableFromInline
var description: String {
String(hashValue, radix: 36, uppercase: false)
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/Atoms/Snapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,19 @@ public struct Snapshot: CustomStringConvertible {
var statements = Set<String>()

for key in caches.keys {
statements.insert(key.debugLabel.quoted)
statements.insert(key.description.quoted)

if let children = graph.children[key] {
for child in children {
statements.insert("\(key.debugLabel.quoted) -> \(child.debugLabel.quoted)")
statements.insert("\(key.description.quoted) -> \(child.description.quoted)")
}
}

if let subscriptions = subscriptions[key]?.values {
for subscription in subscriptions {
let label = "line:\(subscription.location.line)".quoted
statements.insert("\(subscription.location.fileID.quoted) [style=filled]")
statements.insert("\(key.debugLabel.quoted) -> \(subscription.location.fileID.quoted) [label=\(label)]")
statements.insert("\(key.description.quoted) -> \(subscription.location.fileID.quoted) [label=\(label)]")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/AtomsTests/Core/AtomKeyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class AtomKeyTests: XCTestCase {
let key0 = AtomKey(atom)
let key1 = AtomKey(atom, scopeKey: scopeKey)

XCTAssertEqual(key0.debugLabel, "TestAtom<Int>")
XCTAssertEqual(key1.debugLabel, "TestAtom<Int>-scoped:\(scopeKey.debugLabel)")
XCTAssertEqual(key0.description, "TestAtom<Int>")
XCTAssertEqual(key1.description, "TestAtom<Int>-scoped:\(scopeKey.description)")
}
}
4 changes: 2 additions & 2 deletions Tests/AtomsTests/SnapshotTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ final class SnapshotTests: XCTestCase {
"TestAtom<Value2>" -> "TestAtom<Value3>"
"TestAtom<Value3>"
"TestAtom<Value3>" -> "Module/View.swift" [label="line:10"]
"TestAtom<Value4>-scoped:\(scopeKey.debugLabel)"
"TestAtom<Value4>-scoped:\(scopeKey.debugLabel)" -> "Module/View.swift" [label="line:10"]
"TestAtom<Value4>-scoped:\(scopeKey.description)"
"TestAtom<Value4>-scoped:\(scopeKey.description)" -> "Module/View.swift" [label="line:10"]
}
"""
)
Expand Down