File tree Expand file tree Collapse file tree 5 files changed +34
-9
lines changed
Tests/OpenSwiftUICoreTests/Data/Environment Expand file tree Collapse file tree 5 files changed +34
-9
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "originHash" : " 669d1f5a7baa4f6093075d288ac99f536ebb7801497e931b763050191ecbf7d0 " ,
2
+ "originHash" : " c6403e6357703cd6a416b17852a4312a975c4f5a164d0170118352abe1be3e2d " ,
3
3
"pins" : [
4
4
{
5
5
"identity" : " darwinprivateframeworks" ,
6
6
"kind" : " remoteSourceControl" ,
7
7
"location" : " https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git" ,
8
8
"state" : {
9
9
"branch" : " main" ,
10
- "revision" : " 88f975a6b211a5c9b3f2c26e55079b7d8f40275b "
10
+ "revision" : " ad18bd6feaa29e9b138ff7823796c6bc76295fb7 "
11
11
}
12
12
},
13
13
{
25
25
"location" : " https://github.com/OpenSwiftUIProject/OpenGraph" ,
26
26
"state" : {
27
27
"branch" : " main" ,
28
- "revision" : " fed93356e5876f1fc1ae452a9a799e481c8ea170 "
28
+ "revision" : " cc2df5ac75d32f33fb6906b4abfbe18114138c91 "
29
29
}
30
30
},
31
31
{
Original file line number Diff line number Diff line change @@ -46,11 +46,12 @@ package struct CachedEnvironment {
46
46
self . platformCache = PlatformCache ( )
47
47
}
48
48
49
- package mutating func attribute< T> ( id: CachedEnvironment . ID , _ body: ( EnvironmentValues ) -> T ) -> Attribute < T > {
49
+ package mutating func attribute< T> ( id: CachedEnvironment . ID , _ body: @escaping ( EnvironmentValues ) -> T ) -> Attribute < T > {
50
50
guard let item = mapItems. first ( where: { $0. key == id } ) else {
51
- // Blocked by OG's Map
52
- // preconditionFailure("TODO")
53
- return Attribute ( value: body ( environment. value) )
51
+ let map = Map ( environment, body)
52
+ let attribute = Attribute ( map)
53
+ mapItems. append ( MapItem ( key: id, value: attribute. identifier) )
54
+ return attribute
54
55
}
55
56
return item. value. unsafeCast ( to: T . self)
56
57
}
Original file line number Diff line number Diff line change @@ -154,7 +154,7 @@ public struct _GraphInputs {
154
154
preconditionFailure ( " TODO " )
155
155
}
156
156
157
- package func mapEnvironment< T> ( id: CachedEnvironment . ID , _ body: ( EnvironmentValues ) -> T ) -> Attribute < T > {
157
+ package func mapEnvironment< T> ( id: CachedEnvironment . ID , _ body: @escaping ( EnvironmentValues ) -> T ) -> Attribute < T > {
158
158
cachedEnvironment. wrappedValue. attribute ( id: id, body)
159
159
}
160
160
Original file line number Diff line number Diff line change @@ -170,7 +170,7 @@ public struct _ViewInputs {
170
170
)
171
171
}
172
172
173
- package func mapEnvironment< T> ( id: CachedEnvironment . ID , _ body: ( EnvironmentValues ) -> T ) -> Attribute < T > {
173
+ package func mapEnvironment< T> ( id: CachedEnvironment . ID , _ body: @escaping ( EnvironmentValues ) -> T ) -> Attribute < T > {
174
174
base. mapEnvironment ( id: id, body)
175
175
}
176
176
Original file line number Diff line number Diff line change
1
+ //
2
+ // CachedEnvironmentTests.swift
3
+ // OpenSwiftUICoreTests
4
+
5
+ import OpenGraphShims
6
+ @_spi ( ForOpenSwiftUIOnly) import OpenSwiftUICore
7
+ @testable import OpenSwiftUICore
8
+ import OpenSwiftUITestsSupport
9
+ import Testing
10
+
11
+ @MainActor
12
+ struct CachedEnvironmentTests {
13
+ @Test
14
+ func attribute( ) {
15
+ let graph = Graph ( shared: Graph ( ) )
16
+ let globalSubgraph = Subgraph ( graph: graph)
17
+ Subgraph . current = globalSubgraph
18
+ defer { Subgraph . current = nil }
19
+ var env = CachedEnvironment ( . init( value: . init( ) ) )
20
+ let attribute1 = env. attribute ( id: . layoutDirection) { $0. layoutDirection }
21
+ let attribute2 = env. attribute ( id: . layoutDirection) { $0. layoutDirection }
22
+ #expect( attribute1 == attribute2)
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments