File tree Expand file tree Collapse file tree 2 files changed +23
-10
lines changed
Sources/ComposableArchitecture/SharedState
Tests/ComposableArchitectureTests Expand file tree Collapse file tree 2 files changed +23
-10
lines changed Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments