File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
Sources/ComposableArchitecture/SharedState Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -353,7 +353,8 @@ extension Shared {
353353 keyPath: self . keyPath. appending ( path: keyPath) !
354354 )
355355 }
356-
356+
357+ /// Constructs a read-only version of the shared value.
357358 public var reader : SharedReader < Value > {
358359 SharedReader ( reference: self . reference, keyPath: self . keyPath)
359360 }
Original file line number Diff line number Diff line change @@ -37,6 +37,25 @@ public struct SharedReader<Value> {
3737 public init ( _ base: Shared < Value > ) {
3838 self = base. reader
3939 }
40+
41+ /// Constructs a read-only shared value that remains constant.
42+ ///
43+ /// This can be useful for providing ``SharedReader`` values to features in previews and tests:
44+ ///
45+ /// ```swift
46+ /// #Preview {
47+ /// FeatureView(
48+ /// store: Store(
49+ /// initialState: Feature.State(count: .constant(42))
50+ /// ) {
51+ /// Feature()
52+ /// }
53+ /// )
54+ /// )
55+ /// ```
56+ public static func constant( _ value: Value ) -> Self {
57+ Shared ( value) . reader
58+ }
4059
4160 public var wrappedValue : Value {
4261 func open< Root> ( _ reference: some Reference < Root > ) -> Value {
You can’t perform that action at this time.
0 commit comments