Skip to content

Commit

Permalink
remove decodable for now
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Mar 13, 2024
1 parent b430b46 commit b174150
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
10 changes: 0 additions & 10 deletions Sources/ComposableArchitecture/SharedState/Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,6 @@ import Foundation
}
}

extension Shared: Decodable where Value: Decodable {
public init(from decoder: Decoder) throws {
do {
self.init(try decoder.singleValueContainer().decode(Value.self))
} catch {
self.init(try .init(from: decoder))
}
}
}

extension Shared: Encodable where Value: Encodable {
public func encode(to encoder: Encoder) throws {
do {
Expand Down
23 changes: 23 additions & 0 deletions Tests/ComposableArchitectureTests/SharedTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,29 @@ final class SharedTests: XCTestCase {
$0.count = 42
}
}

func test_Codable_AppStorage() throws {
struct State: Codable {
@Shared(.appStorage("count")) var count = 0
init(count: Int = 0) {
self.count = count
}
init(from decoder: any Decoder) throws {
self._count = Shared(wrappedValue: 0, .appStorage("count"))
}
}

let state = State()
state.count = 42

let data = try JSONEncoder().encode(state)

state.count += 1

let decodedState = try JSONDecoder().decode(State.self, from: data)

XCTAssertEqual(decodedState.count, 43)
}
}

@Reducer
Expand Down

0 comments on commit b174150

Please sign in to comment.