Skip to content

Commit b174150

Browse files
committed
remove decodable for now
1 parent b430b46 commit b174150

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Sources/ComposableArchitecture/SharedState/Shared.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,6 @@ import Foundation
224224
}
225225
}
226226

227-
extension Shared: Decodable where Value: Decodable {
228-
public init(from decoder: Decoder) throws {
229-
do {
230-
self.init(try decoder.singleValueContainer().decode(Value.self))
231-
} catch {
232-
self.init(try .init(from: decoder))
233-
}
234-
}
235-
}
236-
237227
extension Shared: Encodable where Value: Encodable {
238228
public func encode(to encoder: Encoder) throws {
239229
do {

Tests/ComposableArchitectureTests/SharedTests.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,29 @@ final class SharedTests: XCTestCase {
639639
$0.count = 42
640640
}
641641
}
642+
643+
func test_Codable_AppStorage() throws {
644+
struct State: Codable {
645+
@Shared(.appStorage("count")) var count = 0
646+
init(count: Int = 0) {
647+
self.count = count
648+
}
649+
init(from decoder: any Decoder) throws {
650+
self._count = Shared(wrappedValue: 0, .appStorage("count"))
651+
}
652+
}
653+
654+
let state = State()
655+
state.count = 42
656+
657+
let data = try JSONEncoder().encode(state)
658+
659+
state.count += 1
660+
661+
let decodedState = try JSONDecoder().decode(State.self, from: data)
662+
663+
XCTAssertEqual(decodedState.count, 43)
664+
}
642665
}
643666

644667
@Reducer

0 commit comments

Comments
 (0)