Skip to content
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

Deprecate Shared's optional dynamic member lookup overload #3145

Merged
merged 5 commits into from
Jun 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,24 @@
"version" : "1.0.0"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
}
},
{
"identity" : "swift-benchmark",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/swift-benchmark",
"state" : {
"revision" : "8163295f6fe82356b0bcf8e1ab991645de17d096",
"version" : "0.1.2"
}
},
{
"identity" : "swift-case-paths",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -63,6 +81,24 @@
"version" : "1.2.2"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
Expand All @@ -72,6 +108,15 @@
"version" : "1.0.2"
}
},
{
"identity" : "swift-macro-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing",
"state" : {
"revision" : "90e38eec4bf661ec0da1bbfd3ec507d0f0c05310",
"version" : "0.3.0"
}
},
{
"identity" : "swift-perception",
"kind" : "remoteSourceControl",
Expand Down
32 changes: 14 additions & 18 deletions Sources/ComposableArchitecture/SharedState/Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ public struct Shared<Value> {
}

public init?(_ base: Shared<Value?>) {
guard let shared = base[dynamicMember: \.self] else { return nil }
self = shared
guard let initialValue = base.wrappedValue
else { return nil }
self.init(
reference: base.reference,
keyPath: base.keyPath.appending(path: \Value?.[default:DefaultSubscript(initialValue)])!
)
}

public var wrappedValue: Value {
Expand Down Expand Up @@ -117,17 +121,13 @@ public struct Shared<Value> {
Shared<Member>(reference: self.reference, keyPath: self.keyPath.appending(path: keyPath)!)
}

@available(
*, deprecated, message: "Use 'Shared($value.optional)' to unwrap optional shared values"
)
public subscript<Member>(
dynamicMember keyPath: WritableKeyPath<Value, Member?>
) -> Shared<Member>? {
guard let initialValue = self.wrappedValue[keyPath: keyPath]
else { return nil }
return Shared<Member>(
reference: self.reference,
keyPath: self.keyPath.appending(
path: keyPath.appending(path: \.[default:DefaultSubscript(initialValue)])
)!
)
Shared<Member>(self[dynamicMember: keyPath])
}

public func assert(
Expand Down Expand Up @@ -358,16 +358,12 @@ extension Shared {
SharedReader(reference: self.reference, keyPath: self.keyPath)
}

@available(
*, deprecated, message: "Use 'SharedReader($value.optional)' to unwrap optional shared values"
)
public subscript<Member>(
dynamicMember keyPath: KeyPath<Value, Member?>
) -> SharedReader<Member>? {
guard let initialValue = self.wrappedValue[keyPath: keyPath]
else { return nil }
return SharedReader<Member>(
reference: self.reference,
keyPath: self.keyPath.appending(
path: keyPath.appending(path: \.[default:DefaultSubscript(initialValue)])
)!
)
SharedReader(self[dynamicMember: keyPath])
}
}
20 changes: 10 additions & 10 deletions Sources/ComposableArchitecture/SharedState/SharedReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ public struct SharedReader<Value> {
}

public init?(_ base: SharedReader<Value?>) {
guard let shared = base[dynamicMember: \.self] else { return nil }
self = shared
guard let initialValue = base.wrappedValue
else { return nil }
self.init(
reference: base.reference,
keyPath: base.keyPath.appending(path: \Value?.[default:DefaultSubscript(initialValue)])!
)
}

public init(_ base: Shared<Value>) {
Expand Down Expand Up @@ -61,17 +65,13 @@ public struct SharedReader<Value> {
SharedReader<Member>(reference: self.reference, keyPath: self.keyPath.appending(path: keyPath)!)
}

@available(
*, deprecated, message: "Use 'SharedReader($value.optional)' to unwrap optional shared values"
)
public subscript<Member>(
dynamicMember keyPath: KeyPath<Value, Member?>
) -> SharedReader<Member>? {
guard let initialValue = self.wrappedValue[keyPath: keyPath]
else { return nil }
return SharedReader<Member>(
reference: self.reference,
keyPath: self.keyPath.appending(
path: keyPath.appending(path: \.[default:DefaultSubscript(initialValue)])
)!
)
SharedReader<Member>(self[dynamicMember: keyPath])
}

#if canImport(Combine)
Expand Down