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
224
224
}
225
225
}
226
226
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
-
237
227
extension Shared : Encodable where Value: Encodable {
238
228
public func encode( to encoder: Encoder ) throws {
239
229
do {
Original file line number Diff line number Diff line change @@ -639,6 +639,29 @@ final class SharedTests: XCTestCase {
639
639
$0. count = 42
640
640
}
641
641
}
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
+ }
642
665
}
643
666
644
667
@Reducer
You can’t perform that action at this time.
0 commit comments