Skip to content

Clean up formatting of Observable macro #69644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 3, 2023
Merged
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
26 changes: 13 additions & 13 deletions lib/Macros/Sources/ObservationMacros/ObservableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public struct ObservableMacro {
return
"""
internal nonisolated func access<Member>(
keyPath: KeyPath<\(observableType), Member>
keyPath: KeyPath<\(observableType), Member>
) {
\(raw: registrarVariableName).access(self, keyPath: keyPath)
\(raw: registrarVariableName).access(self, keyPath: keyPath)
}
"""
}
Expand All @@ -59,10 +59,10 @@ public struct ObservableMacro {
return
"""
internal nonisolated func withMutation<Member, MutationResult>(
keyPath: KeyPath<\(observableType), Member>,
_ mutation: () throws -> MutationResult
keyPath: KeyPath<\(observableType), Member>,
_ mutation: () throws -> MutationResult
) rethrows -> MutationResult {
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
try \(raw: registrarVariableName).withMutation(of: self, keyPath: keyPath, mutation)
}
"""
}
Expand Down Expand Up @@ -202,7 +202,7 @@ extension ObservableMacro: MemberMacro {
return []
}

let observableType = identified.name
let observableType = identified.name.trimmed

if declaration.isEnum {
// enumerations cannot store properties
Expand Down Expand Up @@ -294,7 +294,7 @@ public struct ObservationTrackedMacro: AccessorMacro {
) throws -> [AccessorDeclSyntax] {
guard let property = declaration.as(VariableDeclSyntax.self),
property.isValidForObservation,
let identifier = property.identifier else {
let identifier = property.identifier?.trimmed else {
return []
}

Expand All @@ -306,24 +306,24 @@ public struct ObservationTrackedMacro: AccessorMacro {
"""
@storageRestrictions(initializes: _\(identifier))
init(initialValue) {
_\(identifier) = initialValue
_\(identifier) = initialValue
}
"""

let getAccessor: AccessorDeclSyntax =
"""
get {
access(keyPath: \\.\(identifier))
return _\(identifier)
access(keyPath: \\.\(identifier))
return _\(identifier)
}
"""

let setAccessor: AccessorDeclSyntax =
"""
set {
withMutation(keyPath: \\.\(identifier)) {
_\(identifier) = newValue
}
withMutation(keyPath: \\.\(identifier)) {
_\(identifier) = newValue
}
}
"""

Expand Down